|
From: JTK <je...@gm...> - 2014-10-31 03:38:50
|
Hello,
I was trying to write a cross-implementation package to handle NaNs and INFs
and was a little bit surprised to see that FLOAT-NAN-P and FLOAT-INFINITY-P don't inline for double
floats (or they perform boxing despite being inlined). Is there a way to make them not box?
One could do tricks like the fact that NaNs fail (= x x), but this seems wrong, and I couldn't find a reliable
trick for infinity. [maybe (or (> x most-positive-double-float) (< x most-negative-double-float)) ]
Both functions are proclaimed MAYBE-INLINE.
Many thanks,
- Jan
Example in SBCL 1.2.5
(time
(locally (declare (optimize speed))
(loop for i from 1 to 10000000
for x of-type double-float = (float i 1d0)
when (sb-ext:float-nan-p x)
do (print :found-a-nan))))
Evaluation took:
0.102 seconds of real time
0.102024 seconds of total run time (0.101510 user, 0.000514 system)
100.00% CPU
270,833,595 processor cycles
159,973,376 bytes consed [10M x 8 bytes x 2, so float seems to be boxed]
------
(time
(locally (declare (optimize speed))
(loop for i from 1 to 10000000
for x of-type single-float = (float i 1e0)
when (sb-ext:float-nan-p x)
do (print :found-a-nan))))
Evaluation took:
0.073 seconds of real time
0.073307 seconds of total run time (0.073186 user, 0.000121 system)
100.00% CPU
194,769,260 processor cycles
0 bytes consed
-----
(time
(locally (declare (optimize speed))
(loop for i from 1 to 10000000
for x of-type double-float = (float i 1d0)
when (= (sin x) 0.923423423423423d0)
do (print :found-a-sin))))
Evaluation took:
0.268 seconds of real time
0.269283 seconds of total run time (0.268557 user, 0.000726 system)
100.37% CPU
713,729,790 processor cycles
0 bytes consed |