LOG10

Compute the base-10 (common) logarithm of a positive number.

Category: mathReturns: DOUBLEDialect: Standard

Syntax

LOG10(expr)

Description

## Overview Returns the base-10 (common) logarithm of the input. LOG10 is the preferred function for decibel conversions, order-of-magnitude analysis, and any display-oriented log transform where human-readable powers of 10 matter more than the natural base. For a clean power of 10 such as 100 or 0.001, LOG10 is implemented so that the result is an exact integer without floating-point residue. This is a key reason to prefer LOG10 over LOG(10, x): the latter computes LN(x) / LN(10) and loses a final ULP. ## Behavior - Domain: (0, infinity). Zero and negative values return NULL. - Range: all real numbers. - Returns NULL if the argument is NULL. - Is strictly increasing. - LOG10 of an exact power of 10 (1, 10, 100, 0.001, and similar) returns an exact integer in floating-point. ## Numeric precision - Uses the IEEE 754 double-precision log10 routine. - For integer powers of 10 within the representable range, the result is an exact integer without floating-point residue. - Near x = 1, LOG10 loses precision; consider LOG1P(x - 1) / LN(10) for maximum stability in that regime, or a dedicated LOG1P10 if available. ## Compatibility - Conforms to the SQL standard definition of LOG10 as a scalar DOUBLE function with domain x > 0. - Matches typical mathematical library implementations.

Parameters

NameTypeDescription
exprSpecifies the positive input whose base-10 logarithm is returned. Must be strictly greater than 0; zero and negative values yield NULL.

Examples

-- Basic literal: log10 of 10 is 1
SELECT LOG10(10);
-- Result: 1.0
-- log10 of 100
SELECT LOG10(100);
-- Result: 2.0
-- log10 of 1 is 0
SELECT LOG10(1);
-- Result: 0.0
-- Fractional input
SELECT LOG10(0.001);
-- Result: -3.0
-- Domain violation: non-positive input returns NULL
SELECT LOG10(0), LOG10(-10);
-- Result: NULL, NULL
-- Column use: decibel conversion for signal magnitudes
SELECT sensor_id, 20 * LOG10(magnitude) AS magnitude_db
FROM iot.telemetry.signal_readings
WHERE magnitude > 0;

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →