The different EPSILONs are now computed at compilation time, because the values provided by the C library are not all that precise.

This commit is contained in:
jjgarcia 2004-04-07 15:29:21 +00:00
parent 04525b9812
commit c503e0fc95
3 changed files with 35 additions and 17 deletions

View file

@ -275,22 +275,6 @@ init_number(void)
ECL_SET(@'LEAST-NEGATIVE-NORMALIZED-DOUBLE-FLOAT', num);
ECL_SET(@'LEAST-NEGATIVE-NORMALIZED-LONG-FLOAT', num);
num = make_shortfloat(FLT_EPSILON);
ECL_SET(@'SHORT-FLOAT-EPSILON', num);
ECL_SET(@'SINGLE-FLOAT-EPSILON', num);
num = make_shortfloat(-FLT_EPSILON);
ECL_SET(@'SHORT-FLOAT-NEGATIVE-EPSILON', num);
ECL_SET(@'SINGLE-FLOAT-NEGATIVE-EPSILON', num);
num = make_longfloat(DBL_EPSILON);
ECL_SET(@'DOUBLE-FLOAT-EPSILON', num);
ECL_SET(@'LONG-FLOAT-EPSILON', num);
num = make_longfloat(-DBL_EPSILON);
ECL_SET(@'DOUBLE-FLOAT-NEGATIVE-EPSILON', num);
ECL_SET(@'LONG-FLOAT-NEGATIVE-EPSILON', num);
cl_core.shortfloat_zero = cl_alloc_object(t_shortfloat);
sf(cl_core.shortfloat_zero) = (float)0.0;
cl_core.longfloat_zero = cl_alloc_object(t_longfloat);

View file

@ -342,7 +342,7 @@ write_double(double d, int e, bool shortp)
int n = FPRC; /* was FPRC+1 */
if (shortp)
n = 7;
n = 8;
edit_double(n, d, &sign, buff, &exp);
if (sign==2) {
write_str("#<");

View file

@ -15,6 +15,40 @@
#-ecl-min
(ffi:clines "#include <math.h>")
#.
(flet ((binary-search (f min max)
(do ((new (/ (+ min max) 2) (/ (+ min max) 2)))
((>= min max)
max)
(if (funcall f new)
(if (= new max)
(return max)
(setq max new))
(if (= new min)
(return max)
(setq min new)))))
(epsilon+ (x)
(/= (float 1 x) (+ (float 1 x) x)))
(epsilon- (x)
(/= (float 1 x) (- (float 1 x) x))))
`(eval-when (compile load eval)
(defconstant short-float-epsilon
,(binary-search #'epsilon+ (coerce 0 'short-float) (coerce 1 'short-float)))
(defconstant single-float-epsilon
,(binary-search #'epsilon+ (coerce 0 'single-float) (coerce 1 'single-float)))
(defconstant long-float-epsilon
,(binary-search #'epsilon+ (coerce 0 'double-float) (coerce 1 'double-float)))
(defconstant double-float-epsilon
,(binary-search #'epsilon+ (coerce 0 'long-float) (coerce 1 'long-float)))
(defconstant short-float-negative-epsilon
,(binary-search #'epsilon- (coerce 0 'short-float) (coerce 1 'short-float)))
(defconstant single-float-negative-epsilon
,(binary-search #'epsilon- (coerce 0 'single-float) (coerce 1 'single-float)))
(defconstant long-float-negative-epsilon
,(binary-search #'epsilon- (coerce 0 'double-float) (coerce 1 'double-float)))
(defconstant double-float-negative-epsilon
,(binary-search #'epsilon- (coerce 0 'long-float) (coerce 1 'long-float)))))
(defconstant imag-one #C(0.0 1.0))
(defun isqrt (i)