Re: I Need Help
- Posted by Ad Rienks <Ad_Rienks at COMPUSERVE.COM> Jun 21, 1997
- 921 views
>> There's a simple explanation for why you aren't getting the >> results that you expect. The root of the problem is >>that 0.1 cannot be represented in binary floating-point >>form *exactly*. This means that if you add up ten 0.1's >> you will *not* get 1. > >> Try the following statement in Euphoria: >> ? .1 + .1 + .1 + .1 + .1 + .1 + .1 + .1 + .1 + .1 - 1 >> >> You will not get 0. You will get -1.11e-016. > >in other words a very very small number. >Here is a routine that will correct such errors up to 15 decimal >places: >function round(atom x) > return floor(x*1e15+0.5)/1e15 >end function >Maybe this will be useful to someone. >Regards, > Michael Bolin Hi Michael, Unfortunately, this is not useful to me. If I implement it with: fprint(1, "4.2%f", round(0.745)) what do you think I get? Well, it is 0.74! Strange enough, some of the values x.xx5 round up in the correct way, but not all of them! Is this a bug in my processor (P75), or in the 'binary floating point' routines? I am puzzled over this for a long time already, as I want to do some exac= t financial calculating in Euphoria. Isn't this possible at all, or should = I maybe disable my math coprocessor? Someone please answer me! Ad Rienks