Subject: Re: [ast-developers] Floating point oddities with pow()? Accuracy problem? -------- > > Can someone explain why the the examples below yield a difference? IMO > pow() should deliver the same result as a x*x*x*... sequence. Or not? > > ksh -c 'float x y ; ((x=y=.1 , y=pow(y,4.) , x=x*x*x*x)) ; printf > "%30.30f\n" x-y' > -0.000000000000000000000006617444 > ksh -c 'float x y ; ((x=y=.1 , y=pow(y,6.) , x=x*x*x*x*x*x)) ; printf > "%30.30f\n" x-y' > -0.000000000000000000000000103397 > ksh -c 'float x y ; ((x=y=.1 , y=pow(y,8.) , x=x*x*x*x*x*x*x*x)) ; > printf "%30.30f\n" x-y' > -0.000000000000000000000000001615 > > Platform is Suse 12.1 on AMD64. > > Lionel
The AMD64 has only 18 significant digits with long double and you are asking for 30. This is caused by floating point round off. David Korn [email protected] _______________________________________________ ast-developers mailing list [email protected] http://lists.research.att.com/mailman/listinfo/ast-developers
