Log in

View Full Version : Perhaps I don't understand the function of fabs()


sparrowkc
12-02-2008, 15:04
when I do a
printf("\r\n%d",fabs(-1));

I get some huge number that appears to signal a misdeclaration or something. Why won't this work?

JimWright949
12-02-2008, 15:07
fabs is going to return a value of type float. You are asking printf to interpret this float as an int (%d). To fix it change the %d to %f:
printf("\r\n%f",fabs(-1));

Joe Ross
12-02-2008, 15:49
fabs is going to return a value of type float. You are asking printf to interpret this float as an int (%d). To fix it change the %d to %f:
printf("\r\n%f",fabs(-1));

The microchip printf does not have a %f format. See this thread for some workarounds: http://www.chiefdelphi.com/forums/showthread.php?threadid=63845