mirror of
https://github.com/adtools/clib2.git
synced 2025-12-08 14:59:05 +00:00
- 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. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14948 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
@ -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 \
|
||||
|
||||
@ -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 \
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 */
|
||||
|
||||
@ -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");
|
||||
|
||||
|
||||
62
library/math_inf.c
Normal file
62
library/math_inf.c
Normal file
@ -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 <olsen@sourcery.han.de>
|
||||
* 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 */
|
||||
61
library/math_inff.c
Normal file
61
library/math_inff.c
Normal file
@ -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 <olsen@sourcery.han.de>
|
||||
* 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 */
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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 \
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user