Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

log10 — C23 mathematical function

`log10(x)` from `<math.h>` returns the base-ten logarithm of positive `x` as `double`; `log10f` and `log10l` serve the other floating types. The result states which power of `10` produces the argument.

Version: C23

Syntax

double log10(double x);

log10(x) from <math.h> returns the base-ten logarithm of positive x as double; log10f and log10l serve the other floating types. The result states which power of 10 produces the argument.

The example calls log10(1.0), log10(1000.0), and log10(0.01). Output 0.0 3.0 -2.0 demonstrates positive and negative integral powers of ten plus the neutral point.

For x < 0 there is a domain error, while for zero a pole error may occur; inspect math_errhandling. Underflow of a result extremely close to zero can cause a range error. Annex F returns -∞ for ±0 with FE_DIVBYZERO, +∞ for positive infinity, propagates NaN, and gives positive zero for log10(1).

Examples

#include <math.h>
#include <stdio.h>
int main(void){printf("%.1f %.1f %.1f\n",log10(1.0),log10(1000.0),log10(0.01));return 0;}

Result

0.0 3.0 -2.0

The example calls `log10(1.0)`, `log10(1000.0)`, and `log10(0.01)`. Output `0.0 3.0 -2.0` demonstrates positive and negative integral powers of ten plus the neutral point.

Sources