a stupid problem

Let's talk about algorithms!

Moderator: Board moderators

Post Reply
tuyide
New poster
Posts: 8
Joined: Sat Oct 04, 2003 9:28 am

a stupid problem

Post by tuyide »

can anybody tell me why modf(pow(216,1/double(3)),&s)=1.0?
tuyide
New poster
Posts: 8
Joined: Sat Oct 04, 2003 9:28 am

Post by tuyide »

I mean that its value should be 0 instead of 1
shahriar_manzoor
System administrator & Problemsetter
Posts: 399
Joined: Sat Jan 12, 2002 2:00 am

Floating point error

Post 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
tuyide
New poster
Posts: 8
Joined: Sat Oct 04, 2003 9:28 am

Post by tuyide »

Thank you for help!
Post Reply

Return to “Algorithms”