Free Pascal with Terry

Logarithm Comments



{What are Logarithms anyway, and are they magic? Logarithms (often called just logs) are basically exponents. Exponents have some very interesting properties. If we add two exponents of the same base number, the result is the same as multiplying the two original numbers. Example: 8 * 16 = 128 But 8 = 2^3 and 16 = 2^4, so we can represent it as 2^(3+4) which = 2^7 which also equals 128. Also, if you take that 2^3 and multiply the exponent by 2, which is 2^6, that equals 64 which is the square of 8. Take that 2^3, multiply the exponent by 3, and it becomes 2^9, which is equal to 512, and that is the cube of 8. Therefore, multiplying an exponent is the same as raising that base number to that power, and that multiplier does not even have to be an integer. Also, to get that number's nth root, you just divide the exponent by n. Example: 256 = 2^8, divide 8 by 2 and we get 4. 2^4 = 16, which is also the square root of 256. Take 2^9 = 512, divide that 9 by 3 and we get 2^3 or 8, 8 is the cube root of 512. So around about 1600, a real nut job by the name of John Napier (there is a Wiki page about him) got the brilliant idea that any real positive number can be represented as an exponent of a specific base number. The number e (2.718281828...) is a common base number to use and that is what a natural logarithm (Ln) is based on. Fortunately for us, the algorithm to calculate what a logarithm is for a specific number is built into the math co-processor of most of our CPUs today.} How to get a Logarithms in Pascal: n := Ln(Number); Where n and number have been defined as one of the float types(Real, Single, Double, Extended). In Free Pascal Real Type has been depreceated, but will still compile. On Intel and AMD procewssors it sahould map to the Single Float type. How to return a Log number to a regular number in Pascal: n := Exp(LogNumber); Where n and LogNumber have been defined as one of the float types.