diff --git a/library/GNUmakefile.68k b/library/GNUmakefile.68k index 30e25bf..076ff70 100644 --- a/library/GNUmakefile.68k +++ b/library/GNUmakefile.68k @@ -1,5 +1,5 @@ # -# $Id: GNUmakefile.68k,v 1.54 2005-05-12 13:21:41 obarthel Exp $ +# $Id: GNUmakefile.68k,v 1.55 2005-05-14 10:52:31 obarthel Exp $ # # :ts=8 # @@ -534,6 +534,8 @@ MATH_LIB = \ math_floor.o \ math_fmod.o \ math_fpclassify.o \ + math_inf.o \ + math_inff.o \ math_isfinite.o \ math_isunordered.o \ math_signbit.o \ diff --git a/library/GNUmakefile.os4 b/library/GNUmakefile.os4 index e6caed0..f1bbf5a 100644 --- a/library/GNUmakefile.os4 +++ b/library/GNUmakefile.os4 @@ -1,5 +1,5 @@ # -# $Id: GNUmakefile.os4,v 1.58 2005-05-12 15:07:22 obarthel Exp $ +# $Id: GNUmakefile.os4,v 1.59 2005-05-14 10:52:31 obarthel Exp $ # # :ts=8 # @@ -534,6 +534,8 @@ MATH_LIB = \ math_floor.o \ math_fmod.o \ math_fpclassify.o \ + math_inf.o \ + math_inff.o \ math_isfinite.o \ math_isunordered.o \ math_signbit.o \ diff --git a/library/changes b/library/changes index a0b6b9c..0e921b1 100644 --- a/library/changes +++ b/library/changes @@ -1,3 +1,19 @@ +- fpclassify() now returns FP_ZERO both for 0 and -0. + +- nan() and nanf() now return quiet NaNs. + +- Added internal __inf() and __inff() functions. + +- strtof() now calls nanf() and __inff(), respectively, to produce + the special floating point values for nan/inf/infinity. + +- strtod() now calls nan() and __inf(), respectively, to produce + the special floating point values for nan/inf/infinity. + +- The scanf() family now calls nan() and __inf(), respectively, to + produce the special floating point values for nan/inf/infinity. + + c.lib 1.192 (12.5.2005) - Changed how errors are detected, as returned by Write(), Read() and diff --git a/library/math_fp_support.h b/library/math_fp_support.h index db4e625..bcc9a08 100644 --- a/library/math_fp_support.h +++ b/library/math_fp_support.h @@ -1,5 +1,5 @@ /* - * $Id: math_fp_support.h,v 1.3 2005-01-02 09:07:07 obarthel Exp $ + * $Id: math_fp_support.h,v 1.4 2005-05-14 10:52:31 obarthel Exp $ * * :ts=4 * @@ -80,4 +80,9 @@ union ieee_single /****************************************************************************/ +extern float __inff(void); +extern double __inf(void); + +/****************************************************************************/ + #endif /* _MATH_FP_SUPPORT_H */ diff --git a/library/math_fpclassify.c b/library/math_fpclassify.c index bdd1c28..e36132f 100644 --- a/library/math_fpclassify.c +++ b/library/math_fpclassify.c @@ -1,5 +1,5 @@ /* - * $Id: math_fpclassify.c,v 1.2 2005-05-08 11:27:26 obarthel Exp $ + * $Id: math_fpclassify.c,v 1.3 2005-05-14 10:52:31 obarthel Exp $ * * :ts=4 * @@ -70,7 +70,7 @@ __fpclassify_float(float number) /* Exponent = 255 and fraction = 0.0 -> infinity */ result = FP_INFINITE; } - else if (x.raw[0] == 0) /* ZZZ test against epsilon? */ + else if ((x.raw[0] & 0x7fffffff) == 0) { SHOWMSG("zero"); @@ -122,7 +122,7 @@ __fpclassify_double(double number) /* Exponent = 2047 and fraction = 0.0 -> infinity */ result = FP_INFINITE; } - else if (x.raw[0] == 0 && x.raw[1] == 0) /* ZZZ test against epsilon? */ + else if ((((x.raw[0] & 0x7fffffff) == 0) && (x.raw[1] == 0))) { SHOWMSG("zero"); diff --git a/library/math_inf.c b/library/math_inf.c new file mode 100644 index 0000000..8267d17 --- /dev/null +++ b/library/math_inf.c @@ -0,0 +1,62 @@ +/* + * $Id: math_inf.c,v 1.1 2005-05-14 10:52:31 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +#if defined (FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' (1994) standard. */ + +/****************************************************************************/ + +double +__inf(void) +{ + union ieee_double x; + + /* Exponent = 2047 and fraction = 0.0 -> infinity */ + x.raw[0] = 0x7ff00000; + x.raw[1] = 0x00000000; + + return(x.value); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_inff.c b/library/math_inff.c new file mode 100644 index 0000000..867a8cb --- /dev/null +++ b/library/math_inff.c @@ -0,0 +1,61 @@ +/* + * $Id: math_inff.c,v 1.1 2005-05-14 10:52:31 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2005 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +#if defined (FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' (1994) standard. */ + +/****************************************************************************/ + +float +__inff(void) +{ + union ieee_single x; + + /* Exponent = 255 and fraction = 0.0 -> infinity */ + x.raw[0] = 0x7f800000; + + return(x.value); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_nan.c b/library/math_nan.c index 5950c66..d936151 100644 --- a/library/math_nan.c +++ b/library/math_nan.c @@ -1,5 +1,5 @@ /* - * $Id: math_nan.c,v 1.1 2005-05-08 08:51:29 obarthel Exp $ + * $Id: math_nan.c,v 1.2 2005-05-14 10:52:31 obarthel Exp $ * * :ts=4 * @@ -51,8 +51,8 @@ nan(const char * UNUSED tagp) { union ieee_double x; - /* Exponent = 2047 and fraction != 0.0 */ - x.raw[0] = 0x7ff00000; + /* Exponent = 2047 and fraction != 0.0; this must be a quiet nan. */ + x.raw[0] = 0x7ff80000; x.raw[1] = 0x00000001; return(x.value); diff --git a/library/math_nanf.c b/library/math_nanf.c index e92b84a..56a9742 100644 --- a/library/math_nanf.c +++ b/library/math_nanf.c @@ -1,5 +1,5 @@ /* - * $Id: math_nanf.c,v 1.1 2005-05-08 08:51:29 obarthel Exp $ + * $Id: math_nanf.c,v 1.2 2005-05-14 10:52:31 obarthel Exp $ * * :ts=4 * @@ -51,8 +51,8 @@ nanf(const char * UNUSED tagp) { union ieee_single x; - /* Exponent = 255 and fraction != 0.0 */ - x.raw[0] = 0x7f800001; + /* Exponent = 255 and fraction != 0.0; this must be a quiet nan. */ + x.raw[0] = 0x7fc00001; return(x.value); } diff --git a/library/smakefile b/library/smakefile index 732bcbd..d37dbd6 100644 --- a/library/smakefile +++ b/library/smakefile @@ -1,5 +1,5 @@ # -# $Id: smakefile,v 1.42 2005-05-12 13:21:43 obarthel Exp $ +# $Id: smakefile,v 1.43 2005-05-14 10:52:31 obarthel Exp $ # # :ts=8 # @@ -194,6 +194,8 @@ MATH_OBJ = \ math_floor.o \ math_fmod.o \ math_fpclassify.o \ + math_inf.o \ + math_inff.o \ math_isfinite.o \ math_isunordered.o \ math_signbit.o \ diff --git a/library/stdio_vfscanf.c b/library/stdio_vfscanf.c index 0322208..a47f393 100644 --- a/library/stdio_vfscanf.c +++ b/library/stdio_vfscanf.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_vfscanf.c,v 1.14 2005-05-12 14:50:06 obarthel Exp $ + * $Id: stdio_vfscanf.c,v 1.15 2005-05-14 10:52:31 obarthel Exp $ * * :ts=4 * @@ -599,8 +599,8 @@ vfscanf(FILE *stream, const char *format, va_list arg) the characters back we read during scanning. */ if(maximum_field_width != 0) { - const char infinity[] = "infinity"; - const char nan[] = "nan"; + const char infinity_string[] = "infinity"; + const char infinity_nan[] = "nan"; char chars_read_so_far[80]; size_t num_chars_read_so_far = 0; size_t infinity_match = 0; @@ -610,7 +610,7 @@ vfscanf(FILE *stream, const char *format, va_list arg) { D(("c = '%lc'",c)); - if(tolower(c) == infinity[infinity_match]) + if(tolower(c) == infinity_string[infinity_match]) { SHOWVALUE(infinity_match); @@ -622,7 +622,7 @@ vfscanf(FILE *stream, const char *format, va_list arg) /* Did we match the complete word? */ infinity_match++; - if(infinity_match == sizeof(infinity)-1) + if(infinity_match == sizeof(infinity_string)-1) { SHOWMSG("we have a match for infinity"); break; @@ -643,7 +643,7 @@ vfscanf(FILE *stream, const char *format, va_list arg) SHOWMSG("we have a match for inf"); break; } - else if (tolower(c) == nan[nan_match]) + else if (tolower(c) == infinity_nan[nan_match]) { SHOWVALUE(nan_match); @@ -655,7 +655,7 @@ vfscanf(FILE *stream, const char *format, va_list arg) /* Did we match the complete word? */ nan_match++; - if(nan_match == sizeof(nan)-1) + if(nan_match == sizeof(infinity_nan)-1) { SHOWMSG("we have a match for nan"); @@ -723,29 +723,17 @@ vfscanf(FILE *stream, const char *format, va_list arg) if(infinity_match >= 3) { - union ieee_double x; - SHOWMSG("infinity"); - /* Exponent = 2047 and fraction = 0.0 */ - x.raw[0] = 0x7ff00000; - x.raw[1] = 0x00000000; - - sum = x.value; + sum = __inf(); total_num_chars_read = num_chars_processed = infinity_match; } else if (nan_match >= 3) { - union ieee_double x; - SHOWMSG("not a number"); - /* Exponent = 2047 and fraction != 0.0 */ - x.raw[0] = 0x7ff00000; - x.raw[1] = 0x00000001; - - sum = x.value; + sum = nan(NULL); total_num_chars_read = num_chars_processed = nan_match; } diff --git a/library/stdlib_strtod.c b/library/stdlib_strtod.c index 5a35d45..a8bc413 100644 --- a/library/stdlib_strtod.c +++ b/library/stdlib_strtod.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_strtod.c,v 1.6 2005-05-08 11:27:26 obarthel Exp $ + * $Id: stdlib_strtod.c,v 1.7 2005-05-14 10:52:31 obarthel Exp $ * * :ts=4 * @@ -123,22 +123,14 @@ strtod(const char *str, char ** ptr) /* We begin by checking for the "inf" and "nan" strings. */ if(strcasecmp(str,"inf") == SAME || strcasecmp(str,"infinity") == SAME) { - union ieee_double x; - SHOWMSG("infinity"); str += strlen(str); - /* Exponent = 2047 and fraction = 0.0 */ - x.raw[0] = 0x7ff00000; - x.raw[1] = 0x00000000; - - sum = x.value; + sum = __inf(); } else if (strncasecmp(str,"nan",3) == SAME && (str[3] == '(' || str[3] == '\0')) { - union ieee_double x; - SHOWMSG("not a number"); str += 3; @@ -153,11 +145,7 @@ strtod(const char *str, char ** ptr) str++; } - /* Exponent = 2047 and fraction != 0.0 */ - x.raw[0] = 0x7ff00000; - x.raw[1] = 0x00000001; - - sum = x.value; + sum = nan(NULL); } else { diff --git a/library/stdlib_strtof.c b/library/stdlib_strtof.c index 03c9a2c..11260c1 100644 --- a/library/stdlib_strtof.c +++ b/library/stdlib_strtof.c @@ -1,5 +1,5 @@ /* - * $Id: stdlib_strtof.c,v 1.4 2005-05-08 11:27:26 obarthel Exp $ + * $Id: stdlib_strtof.c,v 1.5 2005-05-14 10:52:31 obarthel Exp $ * * :ts=4 * @@ -123,21 +123,14 @@ strtof(const char *str, char ** ptr) /* We begin by checking for the "inf" and "nan" strings. */ if(strcasecmp(str,"inf") == SAME || strcasecmp(str,"infinity") == SAME) { - union ieee_single x; - SHOWMSG("infinity"); str += strlen(str); - /* Exponent = 255 and fraction = 0.0 */ - x.raw[0] = 0x7f800000; - - sum = x.value; + sum = __inff(); } else if (strncasecmp(str,"nan",3) == SAME && (str[3] == '(' || str[3] == '\0')) { - union ieee_single x; - SHOWMSG("not a number"); str += 3; @@ -152,10 +145,7 @@ strtof(const char *str, char ** ptr) str++; } - /* Exponent = 255 and fraction != 0.0 */ - x.raw[0] = 0x7f800001; - - sum = x.value; + sum = nanf(NULL); } else {