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

Math bug?

 [1/3] from: mbicanic:open:hr at: 29-Jun-2001 21:52


Hi, can you please test this code on your systems ? test-bug: does [ sum: aaa: count: 0 echo %res loop 10000 [ aaa: aaa + 1 bbb: aaa / 10 sum: sum + 0.1 if sum <> bbb [ count: count + 1 print [aaa " :: " sum " <> " bbb ] sum: bbb ] ] print [ "count:" count ] echo none ] Any errors ? I've got 297 errors on my Amiga, and similar results with Windows 95/98 on work. mb

 [2/3] from: alekk::obywatel::pl at: 30-Jun-2001 0:42


----- Original Message ----- From: "mb" <[mbicanic--open--hr]> To: <[rebol-list--rebol--com]> Sent: Friday, June 29, 2001 9:52 PM Subject: [REBOL] Math bug?
> Hi, > can you please test this code on your systems ?
<<quoted lines omitted: 15>>
> Any errors ? > I've got 297 errors on my Amiga, and similar results with Windows 95/98 on
work.
> mb
Quite interesting (windows 98). [loop number :: count from previous error :: sum <> bbb] at start: 67 :: 66 :: 6.69999999999999 <> 6.7 80 :: 13 :: 8 <> 8 ; 2^3 123 :: 43 :: 12.3 <> 12.3 160 :: 37 :: 16 <> 16 ; 2^4 yet nothing interesting except of bug :) 182 :: 22 :: 18.2 <> 18.2 204 :: 22 :: 20.4 <> 20.4 227 :: 23 :: 22.7 <> 22.7 249 :: 22 :: 24.9 <> 24.9 272 :: 23 :: 27.2 <> 27.2 294 :: 22 :: 29.4 <> 29.4 317 :: 23 :: 31.7 <> 31.7 ; and in between 2^5 363 :: 46 :: 36.3000000000001 <> 36.3 ; some errors - second column is 45 until... 633 :: 45 :: 63.3000000000001 <> 63.3 ; of course... 662 :: 29 :: 66.1999999999999 <> 66.2 ; shift - now second column is (22, 23), and now... 1280 :: 11 :: 128 <> 128 ; one 43 and 45 rulez! But loop is going... 2560 :: 22 :: 256 <> 256 ; gotcha! Now 22 - 23 Of course not forever - there are so many powers of two... It's not a bug it is pentium ;) Aleksander K. [alekk--obywatel--pl]

 [3/3] from: joel:neely:fedex at: 29-Jun-2001 16:12


Hi, mb, I got 297 as well, on RedHat Linux 7.1 with View 1.2.0.4.2 installed. However, I'm a little leery of calling these errors as it is well known from numerical analysis that trying to do floating-point with decimal-based values on a binary-based machine is a fruitful source of rounding fuzz . A fairly standard demonstration of round-off fuzz is the pair of functions below. Although the calculations are mathematically equivalent, one starts "at the big end" and the other starts "at the small end" of the summation. As a consequence, their results drift further apart as the number of terms increases.
>> add-up: func [n /local i t s] [
[ t: 0 for i 1 n 1 [s: 1.0 / i t: s * s * s + t] [ ]
>> add-down: func [n /local i t s] [
[ t: 0 for i n 1 -1 [s: 1.0 / i t: s * s * s + t] [ ]
>> add-up 100 == 1.20200740065968 >> add-down 100 == 1.20200740065968
<<quoted lines omitted: 6>>
>> add-up 1000000 == 1.20205690315032 >> add-down 1000000 == 1.20205690315909
HTH! -jn- mb wrote:
> Hi, > can you please test this code on your systems ? >
...
> Any errors ? > I've got 297 errors on my Amiga, and similar results with > Windows 95/98 on work. >
-- ------------------------------------------------------------ Programming languages: compact, powerful, simple ... Pick any two! joel'dot'neely'at'fedex'dot'com

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted