Page 1 of 1

a stupid problem

Posted: Sun Oct 12, 2003 3:47 pm
by tuyide
can anybody tell me why modf(pow(216,1/double(3)),&s)=1.0?

Posted: Sun Oct 12, 2003 4:10 pm
by tuyide
I mean that its value should be 0 instead of 1

Floating point error

Posted: Mon Oct 13, 2003 3:21 am
by shahriar_manzoor
I guess you can solve this by adding a small value

like printf("%lf",modf(pow(216,1/double(3))+1e-15,&s));

Cause is floating point error. The computer is interpreting the value as
5.999999... instead of 6

Posted: Tue Oct 14, 2003 12:34 pm
by tuyide
Thank you for help!