Path: utzoo!attcan!telly!druid!darcy From: darcy@druid.uucp (D'Arcy J.M. Cain) Newsgroups: comp.lang.c Subject: Re: log10(8) Message-ID: <1990Feb26.132441.5339@druid.uucp> Date: 26 Feb 90 13:24:41 GMT References: <3244@servax0.essex.ac.uk> Reply-To: darcy@druid.UUCP (D'Arcy J.M. Cain) Organization: D'Arcy Cain Consulting, West Hill, Ontario Lines: 55 In article <3244@servax0.essex.ac.uk> elzea@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 #include 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@druid) | Thank goodness we don't get all D'Arcy Cain Consulting | the government we pay for. West Hill, Ontario, Canada | (416) 281-6094 |