This came up for Gambit on a specific platform (cough, *Windows*,
cough), so I thought that I'd look at it in SRFI 144. SRFI 144 now has
a pretty good log1+, so I thought I could use it here.
I started with code that gave different results from what's used in
Ubuntu (from fdlibm, I believe), so I used my computable reals package
to test the accuracy of my code and the built-in functions.
When the built-in acosh and asinh proved more accurate, I fiddled over a
number of days. There are only a few things to try, and I think now I
have probably reverse-engineered the fdlibm code. At least, the
built-in functions and these functions have the same mean absolute
error, RMS error, and maximum error over the range and random values I
tested.
I tested this with
~/programs/larceny-0.99-bin-native-ia32-linux86/larceny --path . --r7rs
--program tests/scheme/run/flonum.sps
and got the following errors, which seem to be unrelated to acosh and asinh:
===========================================================
heine:~/programs/srfi-144>
~/programs/larceny-0.99-bin-native-ia32-linux86/larceny --path . --r7rs
--program tests/scheme/run/flonum.sps
Trying /home/lucier/programs/srfi-144/srfi/144.constants.scm
Reading /home/lucier/programs/srfi-144/srfi/144.constants.scm
Trying /home/lucier/programs/srfi-144/srfi/144.body0.scm
Reading /home/lucier/programs/srfi-144/srfi/144.body0.scm
Trying /home/lucier/programs/srfi-144/srfi/144.body.scm
Reading /home/lucier/programs/srfi-144/srfi/144.body.scm
Trying /home/lucier/programs/srfi-144/srfi/144.special.scm
Reading /home/lucier/programs/srfi-144/srfi/144.special.scm
Trying /home/lucier/programs/srfi-144/srfi/144.ffi.scm
Reading /home/lucier/programs/srfi-144/srfi/144.ffi.scm
Running tests for (scheme flonum)
19 tests failed:
Expression:
(fladjacent (fl- fl-least) posinf)
Result:
0.0
Expected:
-0.0
Expression:
(fladjacent (fl- fl-least) one)
Result:
0.0
Expected:
-0.0
Expression:
(test-flnormalized-fraction-exponent fl-least)
Result:
(#t #t #t #t #f)
Expected:
(#t #t #t #t #t)
Expression:
(test-flnormalized-fraction-exponent (fl- fl-least))
Result:
(#t #t #t #t #f)
Expected:
(#t #t #t #t #t)
Expression:
(flnan? (fl+* zero posinf one))
Result:
&error
Expected:
#t
Expression:
(flnan? (fl+* zero neginf one))
Result:
&error
Expected:
#t
Expression:
(flnan? (fl+* posinf zero one))
Result:
&error
Expected:
#t
Expression:
(flnan? (fl+* neginf zero one))
Result:
&error
Expected:
#t
Expression:
(flnan? (fl+* zero posinf nan))
Result:
&error
Expected:
#t
Expression:
(flnan? (fl+* zero neginf nan))
Result:
&error
Expected:
#t
Expression:
(flnan? (fl+* posinf zero nan))
Result:
&error
Expected:
#t
Expression:
(flnan? (fl+* neginf zero nan))
Result:
&error
Expected:
#t
Expression:
(fl+* fl-greatest fl-greatest neginf)
Result:
&error
Expected:
-inf.0
Expression:
(fl+* fl-greatest (fl- fl-greatest) posinf)
Result:
&error
Expected:
+inf.0
Expression:
(flnan? (fl+* nan one one))
Result:
&error
Expected:
#t
Expression:
(flnan? (fl+* one nan one))
Result:
&error
Expected:
#t
Expression:
(flnan? (fl+* one one nan))
Result:
&error
Expected:
#t
Expression:
(flabs negzero)
Result:
-0.0
Expected:
0.0
Expression:
(flhypot (fl/ fl-greatest two) (fl/ fl-greatest two))
Result:
approximately 1.2711610061536462e308
Expected:
approximately 1.271161006153646e308
19 of 1276 tests failed.
===========================================================
This fixes at least one FIXME (in flasinh) and should be more accurate
for flacosh, too.
Here's the patch. I tested fairly extensively on my own.
Brad