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

[REBOL] Re: Core 2.6 - Last minute requests - take your chance!

From: holger:rebol at: 6-Apr-2002 19:06

On Sat, Apr 06, 2002 at 06:19:59PM -0800, Larry Palmiter wrote:
> Fix REBOL comparison operators (<, >, <=, >=, =, <>) so they work correctly > for decimal values. Example: > > >> a: 2 ** 52 > == 4.5035996273705E+15 > >> b: a + 1 > == 4.5035996273705E+15 > >> a = b > == true > >> b - a > == 1 > >> zero? b - a > == false > > In this case a and b test equal although they differ by one. The comparison > operators should give the same results for REBOL decimals as the underlying > C language does for doubles. Note that ZERO?, POSITIVE?, and NEGATIVE? give > the correct results.
The equality operator, and some others, contain an intentional "fuzziness" for decimals to account for platform-specific differences in the way floating point numbers are implemented. Just because they are all of type double in C does not mean they behave in the same way across platforms and math libraries. There are subtle differences, e.g. whether they have hidden precision (temporary calculation with 96-bit precision), whether rounding occurs "down" or "towards zero" etc., and some platforms have known rounding bugs that have to be worked around (e.g. Amiga). The goal is not to precisely emulate the behavior of a particular math library in C, but rather to provide a functionality that strikes a balance between usefulness and efficiency. Having a fuzzy equality (also affecting <= and >= in the = case) is, e.g., important when using loops with decimal numbers. Without fuzzyness the number of loop iterations may be off by one on some platforms, depending on the way the platform handles rounding. -- Holger Kruse [kruse--nordicglobal--com]