operator
Library: Floating point number support (OMFLOAT)
Import : omfloat.xmd Library: Binary coded decimal numbers (OMBCD) Import : ombcd.xmd |
Returns: The natural logarithm of a floating point or bcd number if greater than zero. The argument must be greater than zero. |
define overloaded external float function ln value float x define overloaded external bcd function ln value bcd x
Use ln to calculate the natural logarithm (logarithm to the base e), of either
You must import either omfloat.xmd or ombcd.xmd in your program. Decide whether you want BCD mathematics (excellent for financial calculations) or floating point mathematics (excellent for extremely large numbers).
; Displays the natural logarithm of 10 as a floating point number. import "omfloat.xmd" unprefixed process local float x-var initial {"10"} local float result set result to ln (x-var) output "Natural logarithm of " || "d" % x-var || " = " || "d" % result || "%n" ; Output: "Natural logarithm of 10 = 2.302585092994046".
; Multiply x and y by adding their natural logarithms. ; In this case, display the product obtained by adding the natural logarithms of 100 and 50. import "ombcd.xmd" unprefixed process local bcd x initial {"100"} local bcd y initial {"50"} local bcd lnx local bcd lny local bcd product-from-ln set lnx to ln (x) set lny to ln (y) set product-from-ln to exp(lnx + lny) output "Product of 100 times 50 from adding natural logarithms = " || "d" % product-from-ln || "%n" ; Output: "Product of 100 times 50 from adding natural logarithms = 4999.9999999999967158"
If the result of a natural logarithm 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 an OmniMark program, always surround operators with spaces.