# Board index » delphi » LOG Function

## LOG Function

Hi, I have a little problem that I couldn't solve:

How to write a procedure or function in Pascal (TP 7.0) for LOGarithm
function. I tried with LN, but I can't understand it, and I wish to write my
own function so I don't bother myself with LN.

## Re:LOG Function

##### Quote
In article <4mhh39\$...@bagan.srce.hr> dlu...@jagor.srce.hr (Damir Lukic) writes:
>Hi, I have a little problem that I couldn't solve:
>How to write a procedure or function in Pascal (TP 7.0) for LOGarithm
>function. I tried with LN, but I can't understand it, and I wish to write my
>own function so I don't bother myself with LN.

Well, you *do* have to bother yourself with LN, at least to write a LOG
function:

function log (n : real) : real;

begin
log := ln(n)/ln(10);
end;

This is a bare example that doesn't take into account the range limits of LN
or LOG.  If you know you're using valid values, this should be fine, else
you might want to add a few if's to make it more "friendly".

--
Scott F. Earnest           | We now return you to our regularly scheduled
sc...@whiplash.res.cmu.edu | chaos and mayhem. . . .

## Re:LOG Function

##### Quote
Damir Lukic (dlu...@jagor.srce.hr) wrote:

: Hi, I have a little problem that I couldn't solve:

: How to write a procedure or function in Pascal (TP 7.0) for LOGarithm
: function. I tried with LN, but I can't understand it, and I wish to write my
: own function so I don't bother myself with LN.

I presume that you want the base 10 logarithm.  Is that correct:

function log10( r : real ) : real;       { You may want more bits ... }

begin
log10 := ln( r ) / ln( 10 );
end;
--
Bob Gibson -- gib...@netcom.com
+----------------------------------------------------------------------+
| Microsoft Network is prohibited from redistributing this work in any |
| form, in whole or in part without license.  License to distribute    |
| this work is available to Microsoft at \$500.  Transmission without   |
| permission constitutes an agreement to these terms.                  |
|     Premission is hereby granted to duplicate this restriction.      |
+----------------------------------------------------------------------+

## Re:LOG Function

##### Quote
dlu...@jagor.srce.hr (Damir Lukic) wrote:
>How to write a procedure or function in Pascal (TP 7.0) for LOGarithm
>function. I tried with LN, but I can't understand it, and I wish to write my
>own function so I don't bother myself with LN.

ln is actually log base e.  e is a constant of approximate value of
2.7818.  This is a more useful function in most cases than a log base
10 is, usually.  Given that information, though, you should be able to
come up with something decent for your log base 10 function.

Glenn Grotzinger
Web Page: http://www.geocities.com/Paris/3537
Writer of Excellent Training Manual known as the TP Tutorial.
You may find this material on the web page eventually.
Other interesting things will eventually exist as well.

## Re:LOG Function

##### Quote
dlu...@jagor.srce.hr (Damir Lukic) wrote:
>How to write a procedure or function in Pascal (TP 7.0) for LOGarithm
>function. I tried with LN, but I can't understand it, and I wish to write my
>own function so I don't bother myself with LN.

After some discussion in [comp.programming], I wrote a short math
intro (high-school / college level).  It's available in zipped
MS Word 2.0 for Windows format at

http://home.sol.no/alfps/math_intro.html

Hope this helps,

- Alf

## Re:LOG Function

In <3191DC24....@online.no>, "Alf P. Steinbach" <al...@online.no> writes:

##### Quote
>dlu...@jagor.srce.hr (Damir Lukic) wrote:
>>How to write a procedure or function in Pascal (TP 7.0) for LOGarithm
>>function. I tried with LN, but I can't understand it, and I wish to write my
>>own function so I don't bother myself with LN.

>After some discussion in [comp.programming], I wrote a short math
>intro (high-school / college level).  It's available in zipped
>MS Word 2.0 for Windows format at

>   http://home.sol.no/alfps/math_intro.html

Code would be

FUNCTION Log (InNumber: Real): Real;
BEGIN
If (InNumber = 0.0) Then Log := Infinity Else      { Log zero undefined }
Log := Ln(InNumber)/Ln(10.0);                    { Log of the number }
END;

## Re:LOG Function

"Alf P. Steinbach" <al...@online.no> wrote:

##### Quote
>After some discussion in [comp.programming], I wrote a short math
>intro (high-school / college level).  It's available in zipped
>MS Word 2.0 for Windows format at

Make it ASCII text, as not everyone has MS Word.

Glenn Grotzinger
Web Page: http://www.geocities.com/Paris/3537
Writer of Excellent Training Manual known as the TP Tutorial.
You may find this material on the web page eventually.
Other interesting things will eventually exist as well.

## Re:LOG Function

##### Quote
ldeb...@ibm.net wrote:
>FUNCTION Log (InNumber: Real): Real;
>BEGIN
>   If (InNumber = 0.0) Then Log := Infinity Else      { Log zero undefined }
>     Log := Ln(InNumber)/Ln(10.0);                    { Log of the number }
>END;

Borland Pascal, and all variants thereof, AFAIK can't handle imaginary
numbers.  Would revise this code.

Glenn Grotzinger
Web Page: http://www.geocities.com/Paris/3537
Writer of Excellent Training Manual known as the TP Tutorial.
You may find this material on the web page eventually.
Other interesting things will eventually exist as well.

## Re:LOG Function

##### Quote
Damir Lukic wrote:

> Hi, I have a little problem that I couldn't solve:

> How to write a procedure or function in Pascal (TP 7.0) for LOGarithm
> function. I tried with LN, but I can't understand it, and I wish to write my
> own function so I don't bother myself with LN.

everyone seems to tell you to use ln(x)/ln(10) which would, of
course, work fine, but you say you don't want to use ln. If you really
mean that, I could probably dig up at couple of algorithms for
log base any number.

- KRister