[r6rs-discuss] [Formal] Formal Comment: NaN should be considered a number, not a real
| Date: Tue, 26 Jun 2007 23:00:14 -0400
| From: John Cowan <cowan at ccil.org>
|
| Aubrey Jaffer scripsit:
|
| > You claimed that the result is nan.0+1i. It is not in at least one
| > major Scheme implementation (and has been that way for a while).
|
| Very well. I claim that according to the standard method of adding
| complex numbers, *not* specially hacked to check for NaNs, and
| combined with IEEE float arithmetic, the result will be +nan.0+1i.
SCM's addition routine codes no tests for NaNs. Neither do any of
SCM's other arithmetic operations. Because NaNs in flonums are
contagious, checks for NaNs can be delayed until it is convenient for
the implementation. In SCM's case, this is in the routine which boxes
inexact numbers.
I took as a test case FreeSnell calculating the light transmission
through a 20.nm Al coating on 13.um film of HDPE at 2000 wavelengths
from 900.nm :: 28.0.um at angles from 0 to 89 degrees. This is a
heavily complex (non-real) calculation.
Skipping the check for NaN and infinities improved the CPU-time (the
"User" line in the data) less than 2%, while CPU-time variations were
around 1%. The raw readings are appended.
I also examined the CPU-time of a radiative transfer calculation which
uses no non-real numbers but uses real numbers heavily. It showed
roughly the same penalty for NaN/infinity tests.
SCM has only one (boxed) NaN. Thus EQV? and other functions worked
unchanged when NaN was introduced. But inexact tests are much less
frequent operations than arithmetic in the real-world cases described
above. I have little doubt that the 2% in speed could be recovered by
changing SCM to box more than one NaN.
-=-=-=-=-
Checks for NaN and Inf:
time scm -l film-data.scm
Top substrate IR = 1
IR ~ ? 20.0.nm thick
IR ~ 1.57+1.4e-03i 13.0.um thick (20.5.um optical) ~ 1.780 wave _at_ 11.5.um
Bottom substrate IR = 1
Plotting 2000 samples from 900.nm :: 28.0.um (logarithmic)
real 1m18.568s
user 1m16.849s
sys 0m0.729s
time scm -l film-data.scm
Top substrate IR = 1
IR ~ ? 20.0.nm thick
IR ~ 1.57+1.4e-03i 13.0.um thick (20.5.um optical) ~ 1.780 wave _at_ 11.5.um
Bottom substrate IR = 1
Plotting 2000 samples from 900.nm :: 28.0.um (logarithmic)
real 1m18.788s
user 1m18.069s
sys 0m0.545s
time scm -l film-data.scm
Top substrate IR = 1
IR ~ ? 20.0.nm thick
IR ~ 1.57+1.4e-03i 13.0.um thick (20.5.um optical) ~ 1.780 wave _at_ 11.5.um
Bottom substrate IR = 1
Plotting 2000 samples from 900.nm :: 28.0.um (logarithmic)
real 1m18.014s
user 1m17.265s
sys 0m0.702s
No checks for NaN or Inf:
time scm -l film-data.scm
Top substrate IR = 1
IR ~ ? 20.0.nm thick
IR ~ 1.57+1.4e-03i 13.0.um thick (20.5.um optical) ~ 1.780 wave _at_ 11.5.um
Bottom substrate IR = 1
Plotting 2000 samples from 900.nm :: 28.0.um (logarithmic)
real 1m16.496s
user 1m16.013s
sys 0m0.469s
time scm -l film-data.scm
Top substrate IR = 1
IR ~ ? 20.0.nm thick
IR ~ 1.57+1.4e-03i 13.0.um thick (20.5.um optical) ~ 1.780 wave _at_ 11.5.um
Bottom substrate IR = 1
Plotting 2000 samples from 900.nm :: 28.0.um (logarithmic)
real 1m16.459s
user 1m15.921s
sys 0m0.514s
-=-=-=-=-
Checks for NaN and Inf:
time ./netflow.scm
netflow-1.dat: 25.0.mm of precipitable moisture; ambient is 300.0.K; blackbody _at_ 300.0.K.
real 4m26.370s
user 4m25.365s
sys 0m0.961s
No checks for NaN or Inf:
time ./netflow.scm
netflow-1.dat: 25.0.mm of precipitable moisture; ambient is 300.0.K; blackbody _at_ 300.0.K.
real 4m22.033s
user 4m20.840s
sys 0m1.139s
Received on Sat Jun 30 2007 - 14:48:46 UTC
This archive was generated by hypermail 2.3.0
: Wed Oct 23 2024 - 09:15:01 UTC