# Difference between revisions of "LOG"

Jump to navigation
Jump to search

imported>Clippy m |
imported>Clippy m |
||

Line 36: | Line 36: | ||

{{CodeEnd}} | {{CodeEnd}} | ||

− | : ''Explanation:'' The LOG of the INTEGER value is integer divided by the LOG of 2 to determine the | + | : ''Explanation:'' The LOG of the INTEGER value is integer divided by the LOG of 2 to determine the highest valid bit that will be returned. The FOR loop compares the value with the exponents of two and determines if a bit is ON or OFF as "1" or "0". |

''See also:'' | ''See also:'' | ||

− | [[EXP]] | + | [[EXP]], [[&B]] (binary number) |

{{PageNavigation}} | {{PageNavigation}} |

## Revision as of 08:50, 12 July 2010

The **LOG** math function returns the natural logarithm of a specified numerical value.

*Syntax:* logarithm = LOG(value)

- Value parameter MUST be greater than 0!
- The natural logarithm is the logarithm to the base
**e = 2.718282**(approximately). - The natural logarithm of
*a*is defined as the integral from 1 to*a*of dx/x. - Returns are default SINGLE precision unless the value parameter uses DOUBLE precision.

*Example 1:* FUNCTION to find the base ten logarithm of a numerical value.

FUNCTION Log10#(value AS DOUBLE) STATIC Log10# = LOG(value) / LOG(10.#) END FUNCTION

*Explanation:*The natural logarithm of the value is divided by the base 10 logarithm. The LOG of ten is designated as a DOUBLE precision return by using # after the Log10 value.

*Example 2:* A binary FUNCTION to convert INTEGER values using LOG to find the number of digits the return will be.

FUNCTION Bin$ (n&) FOR p% = 0 TO LOG(n& + .1) \ LOG(2) ' added +.1 to get 0 to work IF n& AND 2 ^ p% THEN s$ = "1" + s$ ELSE s$ = "0" + s$ NEXT p% IF s$ = "" THEN Bin$ = "0" ELSE Bin$ = s$ 'zero return? END FUNCTION

*Explanation:*The LOG of the INTEGER value is integer divided by the LOG of 2 to determine the highest valid bit that will be returned. The FOR loop compares the value with the exponents of two and determines if a bit is ON or OFF as "1" or "0".

*See also:*

*Navigation:*