How to Get Logarithm Base 10 Using LOG(x#)/LOG(10#) in BASIC (31660)






This article was previously published under Q31660

SUMMARY

Microsoft BASIC offers a LOG() function that returns only the natural logarithm, that is, the logarithm to the base e. The number e is a constant approximately equal to 2.718282.

To return a logarithm base b, you can use the following general mathematical formula:

(Log base b of x) = (natural log of x) / (natural log of b)

To return a logarithm base 10, you can use the following specific mathematical formula:

(Log base 10 of x) = (natural log of x) / (natural log of 10)

MORE INFORMATION

The following example defines a Microsoft BASIC single-line function called FNLog10, which returns the logarithm base 10 of a number:
   DEF FNLog10(x#) = LOG(x#) / LOG(10#)
   y#=45
   PRINT "The logarithm base 10 of y# = "; FNLog10(y#)
				
The above formula applies to any product that supports the natural logarithm (LOG) function, such as the following products:

  1. For the Apple Macintosh:

    1. Microsoft QuickBASIC Versions 1.00, 1.00a, 1.00b
    2. Microsoft BASIC Compiler Version 1.00
    3. Microsoft BASIC Interpreter Versions 1.00, 1.01, 2.00, 2.10, 3.00
  2. For the IBM PC and compatibles:

    1. Microsoft BASIC Compiler Versions 5.35 and 5.36 for MS-DOS
    2. Microsoft QuickBASIC Versions 1.00, 1.01, 1.02, 2.00, 2.01, 3.00, 4.00, 4.00b, 4.50 for MS-DOS
    3. Microsoft BASIC Compiler Versions 6.00, 6.00b for MS OS/2 and MS-DOS
    4. Microsoft BASIC Professional Development System (PDS) Version 7.00, 7.10 for MS OS/2 and MS-DOS
    5. Microsoft GW-BASIC Interpreter Versions 3.20, 3.22, and 3.23 for MS-DOS

Modification Type: Minor Last Reviewed: 1/9/2003
Keywords: KB31660