Hi all,
Could someone confirm whether the following is a BUG
with the 'modf' function or me doing something wrong !!!
With the following bit of code:
-----------8<--------------8<----------------------
#include <stdio.h>
#include <math.h>
main() {
int m = 1000;
float value1 = 0.021;
double value2 = 0.021;
double x1, x2;
double n1, n2;
double y1, y2;
x1 = (double)((double)value1 * (double)m);
x2 = (double)((double)value2 * (double)m);
y1 = modf(x1, &n1);
y2 = modf(x2, &n2);
printf("[float] x = %f n = %f y = %f\n", x1, n1, y1);
printf("[double] x = %f n = %f y = %f\n", x2, n2, y2);
}
-----------8<--------------8<----------------------
I get the following output:
[float] x = 21.000000 n = 20.000000 y = 1.000000
[double] x = 21.000000 n = 21.000000 y = 0.000000
In the man page for 'modf' it states the following:
The modf() and modff() functions split a floating-point number x into a
fractional part f and an integer part i such that |f| < 1.0 and (f + i) =
x. Both f and i have the same sign as x. The modf() and modff() functions
return f and store i into the location pointed to by n.
This says that the |f| value should always be less than 1.0. As shown in
the line [float] it returns a value of 1.0 instead of 0.0.
Going by whats in the man page it looks like their is a BUG in the 'modf'
function. Or does this have to do with promoting 'value1' from a float to
a double ???
In any case the 'modf' function looks like it returns '1.0' or is this
really '0.99999999999999999' and the printf's '%f' prints this as a 1.0 ??
Any thoughts on this is appreciated.
Thanks
Joe Spanicek
joe_at_resptk.bhp.com.au
Received on Mon Apr 07 1997 - 02:32:14 NZST