LN

The LN function returns the natural logarithm of a number. The LN and EXP functions are inverse operations.

LN(expression)
expression
An expression that returns a value of any built-in numeric, character-string, or graphic-string data type. A string argument is cast to double-precision floating point before evaluating the function. For more information about converting strings to double-precision floating point, see DOUBLE_PRECISION or DOUBLE. The value of the argument must be greater than zero.

If the data type of the argument is DECFLOAT(n), the result is DECFLOAT(n). Otherwise, the data type of the result is double-precision floating point. If the argument can be null, the result can be null; if the argument is null, the result is the null value.

Note

Results involving DECFLOAT special values: For decimal floating-point values the special values are treated as follows:
  • LN(NaN) returns NaN. 1
  • LN(-NaN) returns NaN. 1
  • LN(Infinity) returns Infinity.
  • LN(-Infinity) returns NaN. 1
  • LN(sNaN) and LN(-sNaN) return a warning or error. 1
  • LN(0) returns -Infinity.
  • LN with a negative argument, including -Infinity, returns NaN. 1

Example

  • Assume the host variable NATLOG is a DECIMAL(4,2) host variable with a value of 31.62.
      SELECT LN(:NATLOG)
        FROM SYSIBM.SYSDUMMY1
    Returns the approximate value 3.45.
1 If *YES is specified for the SQL_DECFLOAT_WARNINGS query option, NaN is returned with a warning.