diff --git a/src/c/number.d b/src/c/number.d index 418003c19..1741f2831 100644 --- a/src/c/number.d +++ b/src/c/number.d @@ -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); diff --git a/src/c/print.d b/src/c/print.d index 752e09039..94228cd02 100644 --- a/src/c/print.d +++ b/src/c/print.d @@ -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("#<"); diff --git a/src/lsp/numlib.lsp b/src/lsp/numlib.lsp index 32b9cba5e..d74bbb3ef 100644 --- a/src/lsp/numlib.lsp +++ b/src/lsp/numlib.lsp @@ -15,6 +15,40 @@ #-ecl-min (ffi:clines "#include ") +#. +(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)