log10(8)

D'Arcy J.M. Cain darcy at druid.uucp
Tue Feb 27 00:24:41 AEST 1990


In article <3244 at servax0.essex.ac.uk> elzea at sersun0.essex.ac.uk (El-Zein A A) writes:
       [With those stupid extra line removed so we don't have to chase
        through multiple screens to see the question!]
>	My calculator gives me 0.9030899 for log(8),
>	While the following code (which I thought would
>	give me the above value of 0.9030899) prints 
>	-312.770165.
>  [...]
>	double l;
>  [...]
>	l = log10(8);
>	printf("%f", l);
>
>	Can anybody tell me why.

I tried the following code using gcc


#include <math.h>
#include <stdio.h>

int main(void)
{
	double l;

	l = log10(8);
	printf("%lf\n", l);
}

And I got the same result as you.  I then made the following changes

[...]
	double l = 8.0;
[...]
	l = log10(l);

and I got the correct answer.  This tells me that I haven't finished
prototyping all of the functions.  In particular the function declaration
in math.h reads:
    double log10();
which is the normal sort of function declaration in pre-ANSI C.  The
following:
    double log10(double x);
as a prototype with ANSI C caused my first version to give the correct result.

With a pre-ANSI C compiler I guess you would have to do the following:
    l = log10((double)(8.0);

I like it in the include file because I'm basically lazy.

-- 
D'Arcy J.M. Cain (darcy at druid)     |   Thank goodness we don't get all 
D'Arcy Cain Consulting             |   the government we pay for.
West Hill, Ontario, Canada         |
(416) 281-6094                     |



More information about the Comp.lang.c mailing list