From: Chris Hanson Date: Sun, 24 Sep 1989 15:13:11 +0000 (+0000) Subject: Eliminate hand-coded flonum parameters in favor of those in "float.h". X-Git-Tag: 20090517-FFI~11773 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=23c702456e01950437ab3d09fa5edd70943e8068;p=mit-scheme.git Eliminate hand-coded flonum parameters in favor of those in "float.h". These new parameters can be generated by hard-params, or if the system has we can use that instead. --- diff --git a/v7/src/microcode/boot.c b/v7/src/microcode/boot.c index c57bb1546..4b27339eb 100644 --- a/v7/src/microcode/boot.c +++ b/v7/src/microcode/boot.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/boot.c,v 9.57 1989/09/20 23:06:26 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/boot.c,v 9.58 1989/09/24 15:12:48 cph Exp $ Copyright (c) 1988, 1989 Massachusetts Institute of Technology @@ -703,7 +703,7 @@ gc_death(code, message, scan, free) #define ID_PRINTER_LENGTH 4 /* TTY height (# chars) */ #define ID_NEW_LINE_CHARACTER 5 /* #\Newline */ #define ID_FLONUM_PRECISION 6 /* Flonum mantissa (# bits) */ -#define ID_FLONUM_EXPONENT 7 /* Flonum exponent (# bits) */ +#define ID_FLONUM_EPSILON 7 /* Flonum epsilon (flonum) */ #define ID_OS_NAME 8 /* OS name (string) */ #define ID_OS_VARIANT 9 /* OS variant (string) */ #define ID_STACK_TYPE 10 /* Scheme stack type (string) */ @@ -732,10 +732,9 @@ DEFINE_PRIMITIVE ("MICROCODE-IDENTIFY", Prim_microcode_identify, 0, 0, 0) FAST_VECTOR_SET (Result, ID_NEW_LINE_CHARACTER, (ASCII_TO_CHAR ('\n'))); FAST_VECTOR_SET - (Result, ID_FLONUM_PRECISION, - (LONG_TO_UNSIGNED_FIXNUM (FLONUM_MANTISSA_BITS))); + (Result, ID_FLONUM_PRECISION, (LONG_TO_UNSIGNED_FIXNUM (DBL_MANT_DIG))); FAST_VECTOR_SET - (Result, ID_FLONUM_EXPONENT, (LONG_TO_UNSIGNED_FIXNUM (FLONUM_EXPT_SIZE))); + (Result, ID_FLONUM_EPSILON, (double_to_flonum ((double) DBL_EPSILON))); FAST_VECTOR_SET (Result, ID_OS_NAME, (char_pointer_to_string (OS_Name))); FAST_VECTOR_SET diff --git a/v7/src/microcode/config.h b/v7/src/microcode/config.h index 51272582c..4439e1fa8 100644 --- a/v7/src/microcode/config.h +++ b/v7/src/microcode/config.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/config.h,v 9.48 1989/09/22 08:44:46 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/config.h,v 9.49 1989/09/24 15:12:53 cph Exp $ Copyright (c) 1987, 1988, 1989 Massachusetts Institute of Technology @@ -121,6 +121,9 @@ typedef unsigned long SCHEME_OBJECT; ULONG_SIZE is the size of an unsigned long in bits. + ******** The following flonum constants have been superseded by the + use of "float.h". ******** + FLONUM_EXPT_SIZE is the number of bits in the largest positive exponent of a (double) floating point number. Note that if excess exponents are used in the representation, @@ -237,9 +240,9 @@ typedef unsigned long SCHEME_OBJECT; #define ULONG_SIZE 32 #define BELL '\007' #define FASL_INTERNAL_FORMAT FASL_68000 -#define FLONUM_EXPT_SIZE 7 -#define FLONUM_MANTISSA_BITS 56 -#define MAX_FLONUM_EXPONENT 127 +/* #define FLONUM_EXPT_SIZE 7 */ +/* #define FLONUM_MANTISSA_BITS 56 */ +/* #define MAX_FLONUM_EXPONENT 127 */ #define HAS_FREXP #ifdef quick /* Bignum code fails for certain variables in registers because of a @@ -263,9 +266,9 @@ typedef unsigned long SCHEME_OBJECT; #define ULONG_SIZE 32 #define BELL '\007' #define FASL_INTERNAL_FORMAT FASL_VAX -#define FLONUM_EXPT_SIZE 7 -#define FLONUM_MANTISSA_BITS 56 /* D format */ -#define MAX_FLONUM_EXPONENT 127 +/* #define FLONUM_EXPT_SIZE 7 */ +/* #define FLONUM_MANTISSA_BITS 56 D format */ +/* #define MAX_FLONUM_EXPONENT 127 */ #define HAS_FLOOR #define HAS_FREXP #define HAS_MODF @@ -331,9 +334,9 @@ longjmp(Exit_Point, NORMAL_EXIT) #else /* not MC68020 */ #define FASL_INTERNAL_FORMAT FASL_68000 #endif /* MC68020 */ -#define FLONUM_EXPT_SIZE 10 -#define FLONUM_MANTISSA_BITS 53 -#define MAX_FLONUM_EXPONENT 1023 +/* #define FLONUM_EXPT_SIZE 10 */ +/* #define FLONUM_MANTISSA_BITS 53 */ +/* #define MAX_FLONUM_EXPONENT 1023 */ #define HAS_FLOOR #define HAS_FREXP #define HAS_MODF @@ -353,9 +356,9 @@ longjmp(Exit_Point, NORMAL_EXIT) #define ULONG_SIZE 32 #define BELL '\007' #define FASL_INTERNAL_FORMAT FASL_HP_9000_500 -#define FLONUM_EXPT_SIZE 10 -#define FLONUM_MANTISSA_BITS 53 -#define MAX_FLONUM_EXPONENT 1023 +/* #define FLONUM_EXPT_SIZE 10 */ +/* #define FLONUM_MANTISSA_BITS 53 */ +/* #define MAX_FLONUM_EXPONENT 1023 */ #define HAS_FLOOR #define HAS_FREXP #define HAS_MODF @@ -375,9 +378,9 @@ longjmp(Exit_Point, NORMAL_EXIT) #define ULONG_SIZE 32 #define BELL '\007' -#define FLONUM_EXPT_SIZE 10 -#define FLONUM_MANTISSA_BITS 53 -#define MAX_FLONUM_EXPONENT 1023 +/* #define FLONUM_EXPT_SIZE 10 */ +/* #define FLONUM_MANTISSA_BITS 53 */ +/* #define MAX_FLONUM_EXPONENT 1023 */ #ifdef sun4 #define MACHINE_TYPE "sun4" @@ -410,9 +413,9 @@ longjmp(Exit_Point, NORMAL_EXIT) #define ULONG_SIZE 32 #define BELL '\007' #define FASL_INTERNAL_FORMAT FASL_BFLY -#define FLONUM_EXPT_SIZE 7 -#define FLONUM_MANTISSA_BITS 56 -#define MAX_FLONUM_EXPONENT 127 +/* #define FLONUM_EXPT_SIZE 7 */ +/* #define FLONUM_MANTISSA_BITS 56 */ +/* #define MAX_FLONUM_EXPONENT 127 */ #include #define HAS_FREXP #define HAS_MODF @@ -428,10 +431,10 @@ longjmp(Exit_Point, NORMAL_EXIT) #define ULONG_SIZE ??? #define BELL '\007' #define FASL_INTERNAL_FORMAT FASL_CYBER -#define FLONUM_EXPT_SIZE 14 -#define FLONUM_MANTISSA_BITS 48 +/* #define FLONUM_EXPT_SIZE 14 */ +/* #define FLONUM_MANTISSA_BITS 48 */ /* Not the full range, or so the manual says. */ -#define MAX_FLONUM_EXPONENT 4095 +/* #define MAX_FLONUM_EXPONENT 4095 */ /* The Cyber180 C compiler manifests a bug in hairy conditional expressions */ #define Conditional_Bug @@ -446,9 +449,9 @@ longjmp(Exit_Point, NORMAL_EXIT) #define ULONG_SIZE 32 #define BELL '\007' #define FASL_INTERNAL_FORMAT FASL_CELERITY -#define FLONUM_EXPT_SIZE 11 -#define FLONUM_MANTISSA_BITS 53 -#define MAX_FLONUM_EXPONENT 2047 +/* #define FLONUM_EXPT_SIZE 11 */ +/* #define FLONUM_MANTISSA_BITS 53 */ +/* #define MAX_FLONUM_EXPONENT 2047 */ #endif #ifdef hp9000s800 @@ -459,9 +462,9 @@ longjmp(Exit_Point, NORMAL_EXIT) #define ULONG_SIZE 32 #define BELL '\007' #define FASL_INTERNAL_FORMAT FASL_HP_SPECTRUM -#define FLONUM_EXPT_SIZE 10 -#define FLONUM_MANTISSA_BITS 53 -#define MAX_FLONUM_EXPONENT 1023 +/* #define FLONUM_EXPT_SIZE 10 */ +/* #define FLONUM_MANTISSA_BITS 53 */ +/* #define MAX_FLONUM_EXPONENT 1023 */ #define FLOATING_ALIGNMENT 0x7 /* Low 3 MBZ for float storage */ #define HAS_FLOOR #define HAS_FREXP @@ -500,9 +503,9 @@ longjmp(Exit_Point, NORMAL_EXIT) #define DBFLT_SIZE 64 #define BELL '\007' #define FASL_INTERNAL_FORMAT FASL_UMAX -#define FLONUM_EXPT_SIZE 10 -#define FLONUM_MANTISSA_BITS 53 -#define MAX_FLONUM_EXPONENT 1023 +/* #define FLONUM_EXPT_SIZE 10 */ +/* #define FLONUM_MANTISSA_BITS 53 */ +/* #define MAX_FLONUM_EXPONENT 1023 */ #define HAS_FLOOR #define HAS_FREXP #define HAS_MODF @@ -517,9 +520,9 @@ longjmp(Exit_Point, NORMAL_EXIT) #define ULONG_SIZE 32 #define BELL '\007' #define FASL_INTERNAL_FORMAT FASL_PYR -#define FLONUM_EXPT_SIZE 10 -#define FLONUM_MANTISSA_BITS 53 -#define MAX_FLONUM_EXPONENT 1023 +/* #define FLONUM_EXPT_SIZE 10 */ +/* #define FLONUM_MANTISSA_BITS 53 */ +/* #define MAX_FLONUM_EXPONENT 1023 */ #endif #ifdef alliant @@ -531,9 +534,9 @@ longjmp(Exit_Point, NORMAL_EXIT) #define ULONG_SIZE 32 #define BELL '\007' #define FASL_INTERNAL_FORMAT FASL_ALLIANT -#define FLONUM_EXPT_SIZE 10 -#define FLONUM_MANTISSA_BITS 53 -#define MAX_FLONUM_EXPONENT 1023 +/* #define FLONUM_EXPT_SIZE 10 */ +/* #define FLONUM_MANTISSA_BITS 53 */ +/* #define MAX_FLONUM_EXPONENT 1023 */ #define HAS_FLOOR #define HAS_FREXP #define HAS_MODF @@ -549,9 +552,9 @@ longjmp(Exit_Point, NORMAL_EXIT) #define ULONG_SIZE 32 /* Flonum (double) size is 64 bits. */ #define FLOATING_ALIGNMENT 0x7 -#define FLONUM_MANTISSA_BITS 53 -#define FLONUM_EXPT_SIZE 10 -#define MAX_FLONUM_EXPONENT 1023 +/* #define FLONUM_MANTISSA_BITS 53 */ +/* #define FLONUM_EXPT_SIZE 10 */ +/* #define MAX_FLONUM_EXPONENT 1023 */ /* Floating point representation uses hidden bit. */ #define FASL_INTERNAL_FORMAT FASL_MIPS #define BELL '\007' diff --git a/v7/src/microcode/flonum.c b/v7/src/microcode/flonum.c index 7163cb883..89e5b4131 100644 --- a/v7/src/microcode/flonum.c +++ b/v7/src/microcode/flonum.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/flonum.c,v 9.28 1989/09/24 13:49:21 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/flonum.c,v 9.29 1989/09/24 15:12:57 cph Exp $ Copyright (c) 1987, 1988, 1989 Massachusetts Institute of Technology @@ -261,19 +261,3 @@ DEFINE_PRIMITIVE ("FLONUM-NORMALIZE", Prim_flonum_normalize, 1, 1, 0) CHECK_ARG (1, FLONUM_P); PRIMITIVE_RETURN (flonum_normalize (ARG_REF (1))); } - -#include "float.h" -#if (FLT_RADIX != 2) -#include "error: floating point radix not 2! Arithmetic won't work." -#endif - -#define FLONUM_CONSTANT(expression) \ -{ \ - PRIMITIVE_HEADER (0); \ - PRIMITIVE_RETURN (expression); \ -} - -DEFINE_PRIMITIVE ("FLONUM-MANTISSA-DIGITS", Prim_flonum_mantissa_digits, 0, 0, 0) - FLONUM_CONSTANT (long_to_integer (DBL_MANT_DIG)) -DEFINE_PRIMITIVE ("FLONUM-EPSILON", Prim_flonum_epsilon, 0, 0, 0) - FLONUM_CONSTANT (double_to_flonum ((double) DBL_EPSILON)) diff --git a/v7/src/microcode/intprm.c b/v7/src/microcode/intprm.c index f893040f9..e0a6ecd04 100644 --- a/v7/src/microcode/intprm.c +++ b/v7/src/microcode/intprm.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/intprm.c,v 1.1 1989/09/20 23:23:20 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/intprm.c,v 1.2 1989/09/24 15:13:01 cph Exp $ Copyright (c) 1989 Massachusetts Institute of Technology @@ -151,7 +151,7 @@ DEFINE_PRIMITIVE ("INTEGER->FLONUM", Prim_integer_to_flonum, 2, 2, 0) PRIMITIVE_RETURN (FIXNUM_TO_FLONUM (integer)); if (bignum_fits_in_word_p (integer, - (((control & 1) != 0) ? FLONUM_MANTISSA_BITS : MAX_FLONUM_EXPONENT), + (((control & 1) != 0) ? DBL_MANT_DIG : DBL_MAX_EXP), 0)) PRIMITIVE_RETURN (BIGNUM_TO_FLONUM (integer)); if ((control & 2) != 0) diff --git a/v7/src/microcode/object.h b/v7/src/microcode/object.h index 70aa68a07..ba329697c 100644 --- a/v7/src/microcode/object.h +++ b/v7/src/microcode/object.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/object.h,v 9.32 1989/09/20 23:10:26 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/object.h,v 9.33 1989/09/24 15:13:04 cph Exp $ Copyright (c) 1987, 1988, 1989 Massachusetts Institute of Technology @@ -433,9 +433,9 @@ extern SCHEME_OBJECT * memory_base; (bignum_fits_in_word_p ((bignum), ((sizeof (long)) * CHAR_BIT), 1)) /* If precision should not be lost, - compare to FLONUM_MANTISSA_BITS instead. */ + compare to DBL_MANT_DIG instead. */ #define BIGNUM_TO_DOUBLE_P(bignum) \ - (bignum_fits_in_word_p ((bignum), MAX_FLONUM_EXPONENT, 0)) + (bignum_fits_in_word_p ((bignum), DBL_MAX_EXP, 0)) /* Flonum Operations */ diff --git a/v7/src/microcode/psbtobin.c b/v7/src/microcode/psbtobin.c index 66a29622d..b7b3a80e1 100644 --- a/v7/src/microcode/psbtobin.c +++ b/v7/src/microcode/psbtobin.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/psbtobin.c,v 9.37 1989/09/21 22:53:12 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/psbtobin.c,v 9.38 1989/09/24 15:12:41 cph Exp $ Copyright (c) 1987, 1989 Massachusetts Institute of Technology @@ -400,7 +400,7 @@ compute_max() fast int expt; Result = 0.0; - for (expt = MAX_FLONUM_EXPONENT; + for (expt = DBL_MAX_EXP; expt != 0; expt >>= 1) { @@ -469,8 +469,7 @@ read_a_flonum () size_in_bits = (read_signed_decimal (portable_file)); if (size_in_bits == 0) return (0); - if ((exponent > MAX_FLONUM_EXPONENT) || - (exponent < -MAX_FLONUM_EXPONENT)) + if ((exponent > DBL_MAX_EXP) || (exponent < DBL_MIN_EXP)) { /* Skip over mantissa */ @@ -488,7 +487,7 @@ read_a_flonum () fast double Normalization; long digit; - if (size_in_bits > FLONUM_MANTISSA_BITS) + if (size_in_bits > DBL_MAN_DIG) { fprintf(stderr, "%s: Some precision may be lost.", diff --git a/v7/src/microcode/scheme.h b/v7/src/microcode/scheme.h index 91fe8890e..6a7e62e26 100644 --- a/v7/src/microcode/scheme.h +++ b/v7/src/microcode/scheme.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/scheme.h,v 9.30 1989/09/20 23:11:23 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/scheme.h,v 9.31 1989/09/24 15:13:08 cph Exp $ Copyright (c) 1987, 1988, 1989 Massachusetts Institute of Technology @@ -96,3 +96,8 @@ MIT in each case. */ #include "extern.h" /* External declarations */ #include "bignum.h" /* Bignum declarations */ #include "prim.h" /* Declarations for primitives. */ +#include "float.h" /* Floating-point parameters */ +#if (FLT_RADIX != 2) +#include "error: floating point radix not 2! Arithmetic won't work." +#endif + diff --git a/v7/src/microcode/unxutl/ymkfile b/v7/src/microcode/unxutl/ymkfile index 24700e93d..5fa531c6b 100644 --- a/v7/src/microcode/unxutl/ymkfile +++ b/v7/src/microcode/unxutl/ymkfile @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/unxutl/Attic/ymkfile,v 1.12 1989/09/24 13:50:26 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/unxutl/Attic/ymkfile,v 1.13 1989/09/24 15:13:11 cph Exp $ Copyright (c) 1989 Massachusetts Institute of Technology @@ -428,7 +428,7 @@ scheme.touch os.touch psbmap.touch usrdef.touch : /* scheme.touch depends also on butterfly.h rename.c */ scheme.touch : scheme.h config.h bkpt.h object.h scode.h sdata.h \ gc.h interp.h stack.h futures.h types.h errors.h returns.h \ - const.h fixobj.h default.h extern.h prim.h intrpt.h + const.h fixobj.h default.h extern.h prim.h intrpt.h float.h os.touch : os.c mul.c unix.c vms.c unknown.c scheme.touch zones.h psbmap.touch : config.h object.h bignum.h bignumint.h bitstr.h types.h \ sdata.h const.h psbmap.h $(GC_HEAD_FILES) comlin.h comlin.c @@ -468,8 +468,7 @@ memmag.o gcloop.o purify.o purutl.o comutl.o : scheme.touch prims.h \ artutl.o : scheme.touch bignum.o : scheme.touch bignumint.h -bigprm.o intprm.o generic.o : scheme.touch prims.h zones.h -flonum.o : scheme.touch prims.h zones.h float.h +bigprm.o flonum.o intprm.o generic.o : scheme.touch prims.h zones.h storage.o : scheme.touch gctype.c diff --git a/v8/src/microcode/object.h b/v8/src/microcode/object.h index 15a7380f3..a4ab711e0 100644 --- a/v8/src/microcode/object.h +++ b/v8/src/microcode/object.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/object.h,v 9.32 1989/09/20 23:10:26 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/object.h,v 9.33 1989/09/24 15:13:04 cph Exp $ Copyright (c) 1987, 1988, 1989 Massachusetts Institute of Technology @@ -433,9 +433,9 @@ extern SCHEME_OBJECT * memory_base; (bignum_fits_in_word_p ((bignum), ((sizeof (long)) * CHAR_BIT), 1)) /* If precision should not be lost, - compare to FLONUM_MANTISSA_BITS instead. */ + compare to DBL_MANT_DIG instead. */ #define BIGNUM_TO_DOUBLE_P(bignum) \ - (bignum_fits_in_word_p ((bignum), MAX_FLONUM_EXPONENT, 0)) + (bignum_fits_in_word_p ((bignum), DBL_MAX_EXP, 0)) /* Flonum Operations */ diff --git a/v8/src/microcode/psbtobin.c b/v8/src/microcode/psbtobin.c index 7dd4b9981..a9c2ba8e3 100644 --- a/v8/src/microcode/psbtobin.c +++ b/v8/src/microcode/psbtobin.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/psbtobin.c,v 9.37 1989/09/21 22:53:12 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/psbtobin.c,v 9.38 1989/09/24 15:12:41 cph Exp $ Copyright (c) 1987, 1989 Massachusetts Institute of Technology @@ -400,7 +400,7 @@ compute_max() fast int expt; Result = 0.0; - for (expt = MAX_FLONUM_EXPONENT; + for (expt = DBL_MAX_EXP; expt != 0; expt >>= 1) { @@ -469,8 +469,7 @@ read_a_flonum () size_in_bits = (read_signed_decimal (portable_file)); if (size_in_bits == 0) return (0); - if ((exponent > MAX_FLONUM_EXPONENT) || - (exponent < -MAX_FLONUM_EXPONENT)) + if ((exponent > DBL_MAX_EXP) || (exponent < DBL_MIN_EXP)) { /* Skip over mantissa */ @@ -488,7 +487,7 @@ read_a_flonum () fast double Normalization; long digit; - if (size_in_bits > FLONUM_MANTISSA_BITS) + if (size_in_bits > DBL_MAN_DIG) { fprintf(stderr, "%s: Some precision may be lost.",