This page is part of the web mail archives of SRFI 70 from before July 7th, 2015. The new archives for SRFI 70 contain all messages, not just those from before July 7th, 2015.
On Jun 23, 2005, at 11:25 PM, William D Clinger wrote:
Bradley Lucier wrote:Re: Your idea of representing common Scheme values as NaNs. I believe it is possible under IEEE 754 that the "hardware" could return a different NaN for each execution of (/ 0. 0.) in the code (for example). (Some proposals have suggested putting the address of the code and/or a rough time stamp in the mantissa.) I'm a bit concerned that a floating-point operation could return a value that would be interpreted by your scheme as #\C (for example).Interesting. Can you tell me of any hardware that actually does this?
Apple's libraries do not put an address or a timestamp in the mantissa of a NaN, but they do put a code indicating where the problem arose. E.g., in
http://developer.apple.com/documentation/mac/PPCNumerics/ PPCNumerics-17.html#HEADING17-45
we find
A NaN may have an associated code that indicates its origin. These codes are listed in Table 2-3. The NaN code is the 8th through 15th most significant bits of the fraction field.Table 2-3 NaN codes Decimal Hexadecimal Meaning 1 0x01 Invalid square root, such as SQRT-1 2 0x02 Invalid addition, such as (+ )+(- ) 4 0x04 Invalid division, such as 0/0 8 0x08 Invalid multiplication, such as 0× 9 0x09 Invalid remainder or modulo, such as x rem 0 17 0x11 Attempt to convert invalid ASCII string 21 0x15 Attempt to create a NaN with a zero code33 0x21 Invalid argument to trigonometric function (such as cos, sin, tan) 34 0x22 Invalid argument to inverse trigonometric function (such as acos, asin, atan) 36 0x24 Invalid argument to logarithmic function (such as log, log10 ) 37 0x25 Invalid argument to exponential function (such as exp, expm1) 38 0x26 Invalid argument to financial function (compound or annuity) 40 0x28 Invalid argument to inverse hyperbolic function (such as acosh, asinh)42 0x2A Invalid argument to gamma function (gamma or lgamma) Note The PowerPC processor always returns 0 for the NaN code.
and the following code gives [descartes:~] lucier% gcc -Wall -o testfp testfp.c -save-temps [descartes:~] lucier% ./testfp 7ff8000000000000 7ff8048000000000 7ff8044000000000 7ff8000000000000 [descartes:~] lucier% cat testfp.c #include <stdio.h> #include <math.h> int main() { union { long long int i; double d; } x, y, z, a; x.d = sqrt(-1.0); y.d = log (-1.0); z.d = acos(2.0); a.d = (1.0 / 0.0) - (1.0 / 0.0); printf("%llx %llx %llx %llx\n", x.i, y.i, z.i, a.i); return 0; }I'd like to have access to those codes if they're available. In other words, I'd like all bit strings that can be interpreted as NaNs by the floating-point system to have external representations.
Brad