Q(uick)BASIC Function: LOG

Quick View

LOG

A math function that returns the natural logarithm of a numeric expression

Worth knowing

Useful and cross-version information about the programming environments of QBasic and QuickBasic.

Syntax
  • EXP(numeric-expression)
  • LOG(numeric-expression)
Description/Parameter(s)
numeric-expression For EXP, a number less than or equal to 88.02969.
For LOG, any positive numeric expression.
Example
PRINT EXP(0), EXP(1) 'Output is: 1 2.718282 PRINT LOG(1), LOG(EXP(1)) 'Output is: 0 1
Syntax
  • LOG(numeric-expression)
Description/Parameter(s)

The numeric expression, n, must be greater than zero.

The natural logarithm is the logarithm to the base e. The constant e is approximately equal to 2.718282.

The LOG function calculates the natural logarithm with single- precision accuracy, unless the argument n is a double-precision value. In this case LOG is calculated with double-precision accuracy.

You may calculate base-10 logarithms by dividing the natural logarithm of the number by the logarithm of 10. The following FUNCTION calculates base-10 logarithms:

  • FUNCTION Log10(X) STATIC
  •    Log10=LOG(X)/LOG(10.#)
  • END FUNCTION
Example

This example prints the value of e and then prints the natural logarithms of e taken to the first, second, and third powers.

CLS ' Clear screen PRINT EXP(1), FOR I = 1 TO 3 PRINT LOG(EXP(1) ^ I), NEXT

Sample Output:

2.718282 1 2 3

See also:

Syntax
  • LOG(numeric-expression)
Description/Parameter(s)

The argument numeric-expression must be greater than zero.

Usage Notes

  • LOG is calculated in single precision if numeric-expression is an integer or single-precision value. If you use any other numeric data type, LOG is calculated in double-precision.
  • The natural logarithm is the logarithm to the base e. The constant e is approximately equal to 2.718282.
  • You can calculate base-10 logarithms by dividing the natural logarithm of the number by the natural logarithm of 10. The following FUNCTION procedure calculates base-10 logarithms:

  • FUNCTION Log10 (X) STATIC
  •    Log10 = LOG(X) / LOG(10#)
  • END FUNCTION
Example

This example prints the value of e and uses the LOG function to calculate the natural logarithm of e taken to the first, second, and third powers.

CLS 'Clear screen. PRINT EXP(1), FOR I = 1 TO 3 PRINT LOG(EXP(1) ^ I), NEXT

Sample Output:

2.718282 1 2 3

See also: