swirl
Guide to OmniMark 8   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
  Related Syntax     Other Library Functions  
operator  

ln

 
 

Library: Floating point number support (OMFLOAT)
Import: omfloat.xmd
Library: Binary coded decimal (BCD) numbers (OMBCD)
Import: ombcd.xmd
Return type: BCD or float

Returns: The natural logarithm of a floating point or bcd number if greater than zero. The argument must be greater than zero.


Declaration

define overloaded external float function 
    ln value float x

define overloaded external bcd function 
    ln value bcd x


Purpose

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).

Floating Point Example:


  ; 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".

BCD Example:


  ; 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.

    Related Syntax
   sqrt
   exp
   log10
   ** (power)
 
  Other Library Functions
   ** (power)
   abs
   ceiling
   exp
   floor
   ln
   log10
   round
   sqrt
   truncate
 
 

Top [ INDEX ] [ CONCEPTS ] [ TASKS ] [ SYNTAX ] [ LIBRARIES ] [ LEGACY LIBRARIES ] [ ERRORS ]

OmniMark 8.2.0 Documentation Generated: March 13, 2008 at 3:27:39 pm
If you have any comments about this section of the documentation, please use this form.

Copyright © Stilo International plc, 1988-2008.