Library: Floating point number support (OMFLOAT)
Import : omfloat.xmd
Library: Binary coded decimal numbers (OMBCD)
Import : ombcd.xmd

Returns: The logarithm base ten for a bcd or a floating point number. The value of x must be greater than 0.

define overloaded external float function
    log10 value float x

define overloaded external bcd function
    log10 value bcd x


Use log10 to calculate the logarithm base ten of:

You must import either ombcd.xmd or omfloat.xmd in your program. Decide whether you want BCD mathematics (excellent for financial calculations) or floating point mathematics (excellent for extremely large numbers).

Floating Point Example:

  ;  Displays the base-10 logarithm of 100  as a floating point number.
  import "omfloat.xmd" unprefixed
      local float x initial {"100"}
      local float result
      set result to log10 (x)
      output "Logarithm (base 10) of " || "d" % x || " = " || "d" % result || "%n"
  ; Output: "Logarithm (base 10) of 100 = 2".

BCD Example:

  ;  How to multiply BCD numbers by adding their base 10 logarithms.
  import "ombcd.xmd" unprefixed
      local bcd x-var initial {"100"}
      local bcd y-var initial {"50"}
      local bcd log10-x
      local bcd log10-y
      local bcd x-times-y
      local bcd logarithm-total
      set log10-x to log10 (x-var)
      output "Logarithm (base 10) of " || "d" % x-var || " = " || "d" % log10-x || "%n"
  ;   Output: "Logarithm (base 10) of 100 = 2".
      set log10-y to log10 (y-var)
      output "Logarithm (base 10) of " || "d" % y-var || " = " || "d" % log10-y || "%n"
  ;   Output: "Logarithm (base 10) of 50 = 1.6989700043360182".
      set logarithm-total to log10-x + log10-y
      set x-times-y to 10 ** logarithm-total
      output "100 times 50 by adding logarithms = " || "d" % x-times-y  || "%n"
  ;   Output: "100 times 50 by adding logarithms = 4999.999999999992".

If the result of a logarithm (base 10) does not fit in the data type of the argument, the value returned is truncated to fit the data type.

If you calculate the natural logarithm of an integer, you need to coerce the integer - to a floating point or BCD number - so that the appropriate function is called. The result will depend on which logarithm function is called.

In OmniMark, always surround operators with spaces.

Related Topics
Other Library Functions