-
-
Save southly/608520 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; xyzzy の epsilon 周りがおかしい | |
;; | |
;; http://twitter.com/TwilightClover/status/26251344464 | |
;; http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/convar_short-_tive-epsilon.html | |
(defconstant my-short-float-epsilon | |
(do* ((fe 1.1s0 fl) | |
(fl 1.0s0 (/ fl 2.0s0))) | |
((not (and (/= (+ 1.0s0 fl) 1.0s0) | |
(> fe fl))) | |
fe))) | |
(defconstant my-short-float-negative-epsilon | |
(do* ((fe 1.1s0 fl) | |
(fl 1.0s0 (/ fl 2.0s0))) | |
((not (and (/= (- 1.0s0 fl) 1.0s0) | |
(> fe fl))) | |
fe))) | |
(dolist (sym '((double-float-epsilon t) | |
(double-float-negative-epsilon nil) | |
(long-float-epsilon t) | |
(long-float-negative-epsilon nil) | |
(short-float-epsilon t) | |
(short-float-negative-epsilon nil) | |
(single-float-epsilon t) | |
(single-float-negative-epsilon nil) | |
(my-short-float-epsilon t) | |
(my-short-float-negative-epsilon nil))) | |
(let ((epsilon (symbol-value (car sym))) | |
(positive (cadr sym))) | |
(format t "~32S = ~32S test = ~S~%" | |
(car sym) | |
epsilon | |
(if positive | |
(not (= (float 1 epsilon) (+ (float 1 epsilon) epsilon))) | |
(not (= (float 1 epsilon) (- (float 1 epsilon) epsilon))))) | |
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; xyzzy 0.2.2.235 | |
double-float-epsilon = 2.220446049250313d-16 test = t | |
double-float-negative-epsilon = 1.110223024625157d-16 test = t | |
long-float-epsilon = 2.220446049250313d-16 test = t | |
long-float-negative-epsilon = 1.110223024625157d-16 test = t | |
short-float-epsilon = 2.220446e-16 test = nil | |
short-float-negative-epsilon = 1.110223e-16 test = nil | |
single-float-epsilon = 2.220446e-16 test = nil | |
single-float-negative-epsilon = 1.110223e-16 test = nil | |
my-short-float-epsilon = 1.192093e-7 test = t | |
my-short-float-negative-epsilon = 5.960464e-8 test = t | |
nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment