From: Chris Hanson Date: Thu, 21 Sep 1989 22:53:12 +0000 (+0000) Subject: Work around bug in portable representation of flonums: the flonum 0.0 X-Git-Tag: 20090517-FFI~11785 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=d0114e1e3eb7ae81f6654a8c3afc447557259526;p=mit-scheme.git Work around bug in portable representation of flonums: the flonum 0.0 is written as "06 + 0". But this program always reads two numbers after the sign, and furthermore treats the first one as the exponent, and the -second- as the size in bits. This caused it to gobble up the type code of the next word by accident. --- diff --git a/v7/src/microcode/psbtobin.c b/v7/src/microcode/psbtobin.c index 366f1d7c5..66a29622d 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.36 1989/09/20 23:04:46 cph Exp $ +$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 $ Copyright (c) 1987, 1989 Massachusetts Institute of Technology @@ -410,24 +410,67 @@ compute_max() return (Result); } +long +read_signed_decimal (stream) + fast FILE * stream; +{ + fast int c = (getc (stream)); + fast long result = (-1); + int negative_p = 0; + while (c == ' ') + c = (getc (stream)); + if (c == '-') + { + negative_p = 1; + c = (getc (stream)); + } + else if (c == '+') + c = (getc (stream)); + if ((c >= '0') && (c <= '9')) + { + result = (c - '0'); + c = (getc (stream)); + while ((c >= '0') && (c <= '9')) + { + result = ((result * 10) + (c - '0')); + c = (getc (stream)); + } + } + if (c != EOF) + ungetc (c, stream); + if (result == (-1)) + { + fprintf (stderr, "%s: Unable to read expected decimal integer\n", + program_name); + inconsistency (); + } + return (negative_p ? (-result) : result); +} + double -read_a_flonum() +read_a_flonum () { Boolean negative; - long size_in_bits, exponent; + long exponent; + long size_in_bits; fast double Result; - getc(portable_file); /* Space */ - negative = ((getc(portable_file)) == '-'); - VMS_BUG(exponent = 0); - VMS_BUG(size_in_bits = 0); - fscanf(portable_file, "%ld %ld", &exponent, &size_in_bits); + getc (portable_file); /* Space */ + negative = ((getc (portable_file)) == '-'); + /* Hair here because portable file format incorrect for flonum 0. */ + exponent = (read_signed_decimal (portable_file)); + if (exponent == 0) + { + int c = (getc (portable_file)); + if (c == '\n') + return (0); + ungetc (c, portable_file); + } + size_in_bits = (read_signed_decimal (portable_file)); if (size_in_bits == 0) - { - Result = 0.0; - } - else if ((exponent > MAX_FLONUM_EXPONENT) || - (exponent < -MAX_FLONUM_EXPONENT)) + return (0); + if ((exponent > MAX_FLONUM_EXPONENT) || + (exponent < -MAX_FLONUM_EXPONENT)) { /* Skip over mantissa */ diff --git a/v8/src/microcode/psbtobin.c b/v8/src/microcode/psbtobin.c index ebb47e440..7dd4b9981 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.36 1989/09/20 23:04:46 cph Exp $ +$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 $ Copyright (c) 1987, 1989 Massachusetts Institute of Technology @@ -410,24 +410,67 @@ compute_max() return (Result); } +long +read_signed_decimal (stream) + fast FILE * stream; +{ + fast int c = (getc (stream)); + fast long result = (-1); + int negative_p = 0; + while (c == ' ') + c = (getc (stream)); + if (c == '-') + { + negative_p = 1; + c = (getc (stream)); + } + else if (c == '+') + c = (getc (stream)); + if ((c >= '0') && (c <= '9')) + { + result = (c - '0'); + c = (getc (stream)); + while ((c >= '0') && (c <= '9')) + { + result = ((result * 10) + (c - '0')); + c = (getc (stream)); + } + } + if (c != EOF) + ungetc (c, stream); + if (result == (-1)) + { + fprintf (stderr, "%s: Unable to read expected decimal integer\n", + program_name); + inconsistency (); + } + return (negative_p ? (-result) : result); +} + double -read_a_flonum() +read_a_flonum () { Boolean negative; - long size_in_bits, exponent; + long exponent; + long size_in_bits; fast double Result; - getc(portable_file); /* Space */ - negative = ((getc(portable_file)) == '-'); - VMS_BUG(exponent = 0); - VMS_BUG(size_in_bits = 0); - fscanf(portable_file, "%ld %ld", &exponent, &size_in_bits); + getc (portable_file); /* Space */ + negative = ((getc (portable_file)) == '-'); + /* Hair here because portable file format incorrect for flonum 0. */ + exponent = (read_signed_decimal (portable_file)); + if (exponent == 0) + { + int c = (getc (portable_file)); + if (c == '\n') + return (0); + ungetc (c, portable_file); + } + size_in_bits = (read_signed_decimal (portable_file)); if (size_in_bits == 0) - { - Result = 0.0; - } - else if ((exponent > MAX_FLONUM_EXPONENT) || - (exponent < -MAX_FLONUM_EXPONENT)) + return (0); + if ((exponent > MAX_FLONUM_EXPONENT) || + (exponent < -MAX_FLONUM_EXPONENT)) { /* Skip over mantissa */