On 29 January 2013 10:50, Lionel Cons <[email protected]> wrote: > 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.
The difference between pow() and manual multiplication (example below) revolves around certain values. Does that ring a bell? ksh -c 'float x y i ; for ((i=-5 ; i < 5 ; i=i+.1)) ; do ((x=y=.1*i , y=pow(y,8) , x=x*x*x*x*x*x*x*x)) ; printf "%30.30f\n" x-y ; done' 0.000000000000000000000000000000 0.000000000000000000000000000000 -0.000000000000000000000211758236 -0.000000000000000000000423516473 0.000000000000000000000211758236 0.000000000000000000000105879118 0.000000000000000000000105879118 -0.000000000000000000000105879118 -0.000000000000000000000211758236 0.000000000000000000000000000000 0.000000000000000000000000000000 -0.000000000000000000000052939559 0.000000000000000000000000000000 0.000000000000000000000052939559 0.000000000000000000000000000000 0.000000000000000000000013234889 0.000000000000000000000013234889 0.000000000000000000000013234889 -0.000000000000000000000019852334 0.000000000000000000000006617444 0.000000000000000000000006617444 0.000000000000000000000003308722 0.000000000000000000000006617444 0.000000000000000000000006617444 0.000000000000000000000000000000 0.000000000000000000000000000000 0.000000000000000000000000827180 0.000000000000000000000000000000 0.000000000000000000000000000000 0.000000000000000000000000620385 -0.000000000000000000000000206795 0.000000000000000000000000000000 -0.000000000000000000000000206795 0.000000000000000000000000000000 0.000000000000000000000000000000 -0.000000000000000000000000051698 -0.000000000000000000000000012924 -0.000000000000000000000000006462 -0.000000000000000000000000006462 0.000000000000000000000000000000 -0.000000000000000000000000000807 0.000000000000000000000000000000 0.000000000000000000000000000000 0.000000000000000000000000000000 0.000000000000000000000000000012 -0.000000000000000000000000000003 0.000000000000000000000000000000 0.000000000000000000000000000000 -0.000000000000000000000000000000 0.000000000000000000000000000000 0.000000000000000000000000000000 -0.000000000000000000000000000000 0.000000000000000000000000000000 0.000000000000000000000000000000 0.000000000000000000000000000000 -0.000000000000000000000000000003 -0.000000000000000000000000000012 0.000000000000000000000000000151 0.000000000000000000000000000000 0.000000000000000000000000000000 -0.000000000000000000000000000807 0.000000000000000000000000001615 0.000000000000000000000000006462 0.000000000000000000000000012924 -0.000000000000000000000000012924 -0.000000000000000000000000025849 -0.000000000000000000000000051698 0.000000000000000000000000000000 0.000000000000000000000000103397 0.000000000000000000000000103397 -0.000000000000000000000000413590 -0.000000000000000000000000413590 0.000000000000000000000000000000 0.000000000000000000000000000000 0.000000000000000000000000000000 0.000000000000000000000000000000 0.000000000000000000000000000000 -0.000000000000000000000001654361 0.000000000000000000000003308722 0.000000000000000000000006617444 0.000000000000000000000000000000 0.000000000000000000000006617444 0.000000000000000000000000000000 0.000000000000000000000013234889 -0.000000000000000000000026469779 -0.000000000000000000000026469779 0.000000000000000000000000000000 -0.000000000000000000000026469779 0.000000000000000000000052939559 0.000000000000000000000052939559 0.000000000000000000000000000000 0.000000000000000000000052939559 -0.000000000000000000000052939559 -0.000000000000000000000105879118 -0.000000000000000000000317637355 0.000000000000000000000000000000 -0.000000000000000000000211758236 0.000000000000000000000000000000 0.000000000000000000000000000000 0.000000000000000000000423516473 0.000000000000000000000000000000 Lionel _______________________________________________ ast-developers mailing list [email protected] http://lists.research.att.com/mailman/listinfo/ast-developers
