InterSystems IRIS Data Platform 2019.2  /  InterSystems SQL Reference

InterSystems SQL Reference
Previous section           Next section
InterSystems: The power behind what matters   

A scalar numeric function that returns the natural logarithm of a given numeric expression.
{fn LOG(expression)}
expression A numeric expression.
LOG returns either the NUMERIC or DOUBLE data type. If expression is data type DOUBLE, LOG returns DOUBLE; otherwise, it returns NUMERIC.
LOG returns the natural logarithm (base e) of expression. LOG returns a value with a precision of 21 and a scale of 18.
LOG can only be used as an ODBC scalar function (with the curly brace syntax).
The following example returns the natural logarithm of an integer:
SELECT {fn LOG(5)} AS Logarithm
returns 1.60943791...
The following Embedded SQL example shows the relationship between the LOG and EXP functions for the integers 1 through 10:
   SET a=1
   WHILE a<11 {
   &sql(SELECT {fn LOG(:a)} INTO :b)
   IF SQLCODE'=0 {
     WRITE !,"Error code ",SQLCODE 
     QUIT }
   ELSE {
     WRITE !,"Logarithm of ",a," = ",b }
   &sql(SELECT ROUND({fn EXP(:b)},12) INTO :c)
   IF SQLCODE'=0 {
     WRITE !,"Error code ",SQLCODE
     QUIT }
   ELSE {
     WRITE !,"Exponential of log ",b," = ",c
     SET a=a+1 }
Note that the ROUND function is needed here to correct for very small discrepancies caused by system calculation limitations. In the above example, ROUND is set arbitrarily to 12 decimal digits for this purpose.
See Also

Previous section           Next section
Send us comments on this page
View this book as PDF   |  Download all PDFs
Copyright © 1997-2019 InterSystems Corporation, Cambridge, MA
Content Date/Time: 2019-08-23 05:52:04