Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] round-off error

From: larry:ecotope at: 4-Jul-2001 21:05

Hi all, Joel mentioned in a recent post that floating-point round-off error can lead to different results when summing a list of numbers of widely varying magnitudes depending on the order in which they are summed. I found an extreme (and extremely artificial) example in a recent Scheme programming book. Consider the following list: janus: [31 2e+34 -1.2345678901235e+80 2749 2939234 -2e+33 3.2e+270 17 -2.4e+270 4.2344294738446e+170 1 -8e+269 0 99]
>> sum: 0 foreach item janus [sum: sum + item] sum
== -1.2345678901235E+80
>> sum: 0 foreach item head reverse janus [sum: sum + item] sum
== 99 Cheers -Larry