Re^2: Help with function

veenu.r.rashid veenu at cbnewsj.ATT.COM
Fri Jan 19 07:27:08 AEST 1990


In article <2385 at ektools.UUCP> randolph at ektools.UUCP (Gary L. Randolph) writes:
>In article <3198 at cbnewsj.ATT.COM> veenu at 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 got quite a flurry of messages about the problem above which I
posted to the net..  The vast majority of the messages pointed out one
obvious flaw:  the usage of strtod() takes two args.  This is quite right.
I used atof(), which takes one argument, in the actual program, but
posted strtod(), since I typed in the message on the fly.  I apologize
for the confusion, but the other part of the responses did help in a
major way -- using fabs().  As it turns out, the abs() macro definition
tends to return int, (but not always!), while fabs() returns the correct
floating point value.  Now, is this just a macro characteristic or is it
the compiler I'm using.  (*Disclaimer*  The question is academic in my
case!)

Thanks very much to all who replied to the original posting :-)



ruze




att!mtmfi!ruze

AT&T Bell Laboratories	(201) 957-6684



More information about the Comp.lang.c mailing list