log10
Use the log10() function to calculate the base-10 (common) logarithm of a numeric value.
Syntax
log10(<number>)Parameters
number
integer, float
Yes
The numeric value for which to calculate the base-10 logarithm. The value must be greater than 0.
Returns
Type: float
Description: The log10() function returns the base-10 logarithm of the input value. If the input is null, zero, or negative, the function returns null or NaN.
Usage notes
Input type: XQL doesn't support NaN or infinite values as input and these value types also can not be returned.
Valid Input Range: The input
numbermust be strictly greater than 0. The base-10 logarithm is undefined for zero and negative numbers.Zero Input:
log10(0)returns negative infinity ornull.Negative Input:
log10(x)forx < 0returnsNaNornull.Null Handling: If the input expression is
null, the function returnsnull.Key Values:
log10(1)returns0.0,log10(10)returns1.0,log10(100)returns2.0,log10(1000)returns3.0.Relationship:
log10(x)is equivalent tolog(x, 10).Common Use Cases: This function is typically used within the
alterstage for decibel calculations, order-of-magnitude analysis, pH calculations, and logarithmic scaling of data.
Examples
Example 1: Calculate base-10 logarithm of literal values
Goal: Calculate the base-10 logarithm for specific numeric literals to verify known mathematical results.
XQL code:
Explanation: log10(1) returns 0.0, log10(100) returns 2.0 (since 10^2 = 100), and log10(1000) returns 3.0 (since 10^3 = 1000).
Output:
0.0
2.0
3.0
Example 2: Calculate base-10 logarithm from a field value
Goal: Calculate the base-10 logarithm of values stored in a dataset field to determine their order of magnitude.
XQL code:
Explanation: This query computes the base-10 logarithm for each positive value in numeric_value, then uses floor() to determine the order of magnitude. For example, a value of 500 has log10 ≈ 2.699, so its order of magnitude is 2 (hundreds).
Output:
101
5.0
0.69897
0
102
500.0
2.69897
2
103
10000.0
4.0
4
Example 3: Use log10 for decibel calculation
Goal: Calculate a decibel-like ratio using the base-10 logarithm.
XQL code:
Explanation: This query calculates a decibel-like ratio using the formula 10 * log10(ratio), which is a common pattern in signal processing and audio engineering.
Output:
101
100.0
1.0
100.0
20.0
102
50.0
5.0
10.0
10.0
103
1000.0
10.0
100.0
20.0
Related articles
Datasets:
xdr_data
Last updated
Was this helpful?
