Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎

### LOG

 Keyword Abbreviation Token (hex) Version(s) Classification LOG none BC 1.0+ Function

LOG value )

 Parameters Type Legal Value(s) Note(s) value Numeric any positive

 Returns Type Value(s) Note(s) power Floating-point -88.7228392 to +88.0296919

 Purpose
Calculate the "Napierian" or Natural Logarithm.

 Remarks
The LOG function is rather excentric; it calculates a power needed to raise e such that result is the given value.  In math symbols, it solves for power in the equation
value = e power
where e is the "natural" base of approximately 2.71828183.  The LOG function is typically used to scale values or solve equations which involve exponential growth.  Examples include bacteria population growth, charging of capacitors, compound interest, and radioactive decay.

The abstract base of e is pretty meaningless to people, who often find the "common log" (log base 10) to be more useful.  For computers, "binary log" (log base 2) is often more useful.  You can calculate the value of log to an arbitrary base in BASIC with this formula:
desiredLog = LOG( value ) / LOG( base )

If the value given to LOG is zero or negative, an ILLEGAL QUANTITY ERROR happens.  If the value is omitted or not a valid expression, SYNTAX ERROR is generated.  If the value is not numeric, a TYPE MISMATCH ERROR occurs.

LOG is the inverse of EXP function.

Examples:
 ```PRINT LOG(1000) : REM 'natural' log 6.90775528 READY. PRINT LOG(1000) / LOG(10) : REM 'common' log 3 READY. PRINT LOG(256) / LOG(2) : REM 'binary' log 8 READY. ```

 Compare With

 Contrast With