Skip to content

Instantly share code, notes, and snippets.

@miyamuko
Created October 3, 2010 10:15
Show Gist options
  • Save miyamuko/608467 to your computer and use it in GitHub Desktop.
Save miyamuko/608467 to your computer and use it in GitHub Desktop.
#xyzzy の epsilon 周りがおかしい
;; xyzzy の epsilon 周りがおかしい
;;
;; http://twitter.com/TwilightClover/status/26251344464
;; http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/convar_short-_tive-epsilon.html
(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)))
(let ((epsilon (symbol-value (car sym)))
(positive (cadr sym)))
(format t "~30S = ~@30S, test = ~S~%"
(car sym)
epsilon
(if positive
(not (= (float 1 epsilon) (+ (float 1 epsilon) epsilon)))
(not (= (float 1 epsilon) (- (float 1 epsilon) epsilon)))))
))
;; 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)
nil
;; SBCL 1.0.37
DOUBLE-FLOAT-EPSILON = 1.1102230246251568d-16 (test = T)
DOUBLE-FLOAT-NEGATIVE-EPSILON = 5.551115123125784d-17 (test = T)
LONG-FLOAT-EPSILON = 1.1102230246251568d-16 (test = T)
LONG-FLOAT-NEGATIVE-EPSILON = 5.551115123125784d-17 (test = T)
SHORT-FLOAT-EPSILON = 5.960465e-8 (test = T)
SHORT-FLOAT-NEGATIVE-EPSILON = 2.9802326e-8 (test = T)
SINGLE-FLOAT-EPSILON = 5.960465e-8 (test = T)
SINGLE-FLOAT-NEGATIVE-EPSILON = 2.9802326e-8 (test = T)
;; CLISP 2.48
DOUBLE-FLOAT-EPSILON = 1.1102230246251568d-16 (test = T)
DOUBLE-FLOAT-NEGATIVE-EPSILON = 5.551115123125784d-17 (test = T)
LONG-FLOAT-EPSILON = 5.4210108624275221706L-20 (test = T)
LONG-FLOAT-NEGATIVE-EPSILON = 2.7105054312137610853L-20 (test = T)
SHORT-FLOAT-EPSILON = 7.6295s-6 (test = T)
SHORT-FLOAT-NEGATIVE-EPSILON = 3.81476s-6 (test = T)
SINGLE-FLOAT-EPSILON = 5.960465E-8 (test = T)
SINGLE-FLOAT-NEGATIVE-EPSILON = 2.9802326E-8 (test = T)
NIL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment