Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!rochester!kodak!ektools!randolph From: randolph@ektools.UUCP (Gary L. Randolph) Newsgroups: comp.lang.c Subject: Re: Help with function Keywords: abs(), strtod(), don't work Message-ID: <2385@ektools.UUCP> Date: 11 Jan 90 15:18:26 GMT References: <3198@cbnewsj.ATT.COM> Sender: randolph@ektools (Gary L. Randolph) Reply-To: randolph@ektools.UUCP (Gary L. Randolph) Distribution: na Organization: Eastman Kodak, Dept. 47, Rochester NY Lines: 30 In article <3198@cbnewsj.ATT.COM> veenu@cbnewsj.ATT.COM (veenu.r.rashid) writes: > On the compiler I'm using, abs() and strtol() seem to generate incorrect >or at least inaccurate results. I'm using the following code: >main(int argc, char *argv[]) >{ > double temp; > > temp = strtod(argv[1]); /* get the argument as a double */ > printf("Absolute value of %g is %g\n", temp, abs(temp)); >} >Any code, suggestions, comments greatly appreciated. Well, I can't duplicate the problem. I am using cfront 2.0 on a Sun and all seems to work fine but I did have to make the following changes to the code: I used fabs() rather than abs() I called strtod as follows: temp = strtod(argv[1], NULL) /*ANSI definition*/ your results was impossible. If that's all you are missing, I would be dissappointed that the compiler didn't generate an error. This is the sort of thing that would cause the described flakey behavior. : - ) Gary