[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: guile-core-20020426 and IEEE 754 arithmetic
From: |
Nelson H. F. Beebe |
Subject: |
Re: guile-core-20020426 and IEEE 754 arithmetic |
Date: |
Thu, 16 May 2002 07:06:41 -0600 (MDT) |
Thanks to Marius Vollmer <address@hidden> and John W. Eaton
<address@hidden> for the reports of much improved handling of
floating-point output in the current guile development sources!
John asked about this fragment of my report:
>> ...
>> | (1) Output of small numbers is incorrect:
>> |
>> | (use-modules (ice-9 format))
>> | (let ((ratio (- 1.0 (expt 2 -53))))
>> | (while (> ratio (/ ratio 2))
>> | (format #t "~25,15g~%" ratio)
>> | (set! ratio (* ratio 2)))
>> | (format #t "~25,15g~%" ratio))
>> |
>> | At Marius' suggestion, this was mostly fixed by this patch:
>> |
>> | % diff /usr/local/share/guile/site/ice-9/format.scm*
>> | 1445c1445
>> | < (define format:fn-max 400) ; max. number of number
>> digits
>> | ---
>> | > (define format:fn-max 200) ; max. number of number
>> digits
>>
>> It's not clear from the diff which is the old and new. If it is
>> supposed to be 400, then this change appears to be in the newer
>> sources.
>> ...
Apologies for not making my diff of format.scm clearer: the changed
file increased the buffer size from 200 to 400, fixing the problem
with the display of large floating-point numbers.
>> If (- 0.0) is a valid way to create a signed zero,...
Another way to get a negative zero is (/ -1 Infinity): here's a
summary of what my hoc, and guile and some other Lisp systems, do with
this:
hoc-7.0.x:
hoc> x = 0
hoc> __hex(x)
0x00000000_00000000 == 0 0
hoc> y = -0
hoc> __hex(y)
0x80000000_00000000 == 0 0
hoc> y
-0
hoc> z = 1 / -Inf
hoc> __hex(z)
0x80000000_00000000 == 0 0
bigloo (2.5a)
1:=> -0.0
0.0 !WRONG
1:=> (- 0.0)
0.0 !WRONG
1:=> (/ -1 (/ 1.0 0.0))
0.0 !WRONG
guile-core-20020426 (1.5.6):
guile> -0.0
0.0 !WRONG
guile> (- 0.0)
0.0 !WRONG
guile> (/ -1 (/ 1.0 0.0))
0.0 !WRONG
mzscheme 200alpha12 (PLT Scheme):
> -0.0
-0.0 !OK
> (- 0.0)
-0.0 !OK
> (/ -1 (/ 1.0 0.0))
-0.0 !OK
Scheme Release 7.3.1 Microcode Version 11.146 Runtime 14.166 (MIT Scheme):
1 ]=> -0.0
;Value: 0. !WRONG
1 ]=> (- 0.0)
;Value: 0. !WRONG
1 ]=> (/ -1 (/ 1.0 0.0))
;Value: 0. !WRONG
[By the way, that implementation produces #[+inf] and #[NaN] for
Infinity and NaN.]
emacs-21.2.2:
(- 0.0)
-0.0 !OK
-0.0
-0.0 !OK
(/ -1 (/ 1.0 0.0))
-0.0 !OK
clisp 2.28 (released 2002-03-03):
[1]> (- 0.0)
0.0 !WRONG
[1]> -0.0
0.0 !WRONG
[2]> (/ -1.0e-300 1.0e+300)
*** - floating point underflow !BOTCH
[3] (/ -1 (/ 1.0 0.0))
*** - division by zero !BOTCH
gcl 2.2.2:
>-0.0
0.0 !WRONG
>(- 0.0)
-0.0 !OK
>(/ -1.0e-300 1.0e+300)
-0.0 !OK
>(/ -1 (/ 1.0 0.0))
Error: Zero divisor. !BOTCH
A caution for implementers: when I tested hoc on several different
platforms, I found that on a few, it produced 0 instead of -0: that is
due to the underlying C printf() function's defective handling of
negative zero. I will add code in the next hoc release to handle that
special case.
Similar experiments in with 50+ C, 35_ C++, and 30+ Fortran compilers,
produce mixed results: correct handling of IEEE 754 negative zero
remains elusive in those languages, despite that fact that the
arithmetic system is now more than two decades old, and is in
universal use on 100M+ desktop computer systems.
-------------------------------------------------------------------------------
- Nelson H. F. Beebe Tel: +1 801 581 5254 -
- Center for Scientific Computing FAX: +1 801 585 1640, +1 801 581 4148 -
- University of Utah Internet e-mail: address@hidden -
- Department of Mathematics, 110 LCB address@hidden address@hidden -
- 155 S 1400 E RM 233 address@hidden -
- Salt Lake City, UT 84112-0090, USA URL: http://www.math.utah.edu/~beebe -
-------------------------------------------------------------------------------