1
0
mirror of https://github.com/adtools/clib2.git synced 2025-12-08 14:59:05 +00:00

- Small fixes to the scanf() family.

git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14938 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
Olaf Barthel
2005-05-08 11:27:26 +00:00
parent 2548af2b4b
commit 89b568bcb8
7 changed files with 727 additions and 330 deletions

View File

@ -50,6 +50,10 @@
- Added fabsf() for C99.
- The scanf() family now supports the %hh, %j, %t and %z modifiers and the
%a/%A conversions for C99. The %j is treated like %ll; %t and %z are treated
like %l. Also, the "inf"/"infinity"/"nan"/"nan()" keywords are processed.
c.lib 1.191 (9.4.2005)

View File

@ -1,5 +1,5 @@
/*
* $Id: math_fpclassify.c,v 1.1 2005-05-08 08:51:29 obarthel Exp $
* $Id: math_fpclassify.c,v 1.2 2005-05-08 11:27:26 obarthel Exp $
*
* :ts=4
*
@ -54,16 +54,44 @@ __fpclassify_float(float number)
x.value = number;
D(("number = 0x%08lx",x.raw[0]));
if((x.raw[0] & 0x7f800000) == 0x7f800000 && (x.raw[0] & 0x007fffff) != 0)
result = FP_NAN; /* Exponent = 255 and fraction != 0.0 -> not a number */
{
SHOWMSG("not a number");
/* Exponent = 255 and fraction != 0.0 -> not a number */
result = FP_NAN;
}
else if ((x.raw[0] & 0x7fffffff) == 0x7f800000)
result = FP_INFINITE; /* Exponent = 255 and fraction = 0.0 -> infinity */
{
SHOWMSG("infinity");
/* Exponent = 255 and fraction = 0.0 -> infinity */
result = FP_INFINITE;
}
else if (x.raw[0] == 0) /* ZZZ test against epsilon? */
result = FP_ZERO; /* Both exponent and fraction are zero -> zero */
{
SHOWMSG("zero");
/* Both exponent and fraction are zero -> zero */
result = FP_ZERO;
}
else if ((x.raw[0] & 0x7f800000) == 0)
result = FP_SUBNORMAL; /* Exponent = 0 -> subnormal */
{
SHOWMSG("subnormal");
/* Exponent = 0 -> subnormal (IEEE 754) */
result = FP_SUBNORMAL;
}
else
{
SHOWMSG("normal");
result = FP_NORMAL;
}
SHOWVALUE(result);
return(result);
}
@ -78,16 +106,44 @@ __fpclassify_double(double number)
x.value = number;
D(("number = 0x%08lx%08lx",x.raw[0],x.raw[1]));
if(((x.raw[0] & 0x7ff00000) == 0x7ff00000) && ((x.raw[0] & 0x000fffff) != 0 || (x.raw[1] != 0)))
result = FP_NAN; /* Exponent = 2047 and fraction != 0.0 -> not a number */
{
SHOWMSG("not a number");
/* Exponent = 2047 and fraction != 0.0 -> not a number */
result = FP_NAN;
}
else if (((x.raw[0] & 0x7fffffff) == 0x7ff00000) && (x.raw[1] == 0))
result = FP_INFINITE; /* Exponent = 2047 and fraction = 0.0 -> infinity */
{
SHOWMSG("infinity");
/* Exponent = 2047 and fraction = 0.0 -> infinity */
result = FP_INFINITE;
}
else if (x.raw[0] == 0 && x.raw[1] == 0) /* ZZZ test against epsilon? */
result = FP_ZERO; /* Both exponent and fraction are zero -> zero */
{
SHOWMSG("zero");
/* Both exponent and fraction are zero -> zero */
result = FP_ZERO;
}
else if ((x.raw[0] & 0x7fff0000) == 0)
result = FP_SUBNORMAL; /* Exponent = 0 -> subnormal */
{
SHOWMSG("subnormal");
/* Exponent = 0 -> subnormal (IEEE 754) */
result = FP_SUBNORMAL;
}
else
{
SHOWMSG("normal");
result = FP_NORMAL;
}
SHOWVALUE(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_vfprintf.c,v 1.15 2005-05-08 08:51:29 obarthel Exp $
* $Id: stdio_vfprintf.c,v 1.16 2005-05-08 11:27:26 obarthel Exp $
*
* :ts=4
*
@ -37,8 +37,6 @@
/****************************************************************************/
/*#define DEBUG*/
#ifndef _STDIO_HEADERS_H
#include "stdio_headers.h"
#endif /* _STDIO_HEADERS_H */
@ -76,6 +74,8 @@ get_num_leading_digits(__long_double_t v,int radix)
{
int num_digits;
SHOWVALUE(radix);
if(v < radix)
{
num_digits = 1;
@ -124,7 +124,7 @@ vfprintf(FILE * stream,const char * format, va_list arg)
parameter_size_long_long,
parameter_size_long_double,
parameter_size_intmax_t,
parameter_size_default,
parameter_size_default
};
struct iob * iob = (struct iob *)stream;
@ -892,6 +892,8 @@ vfprintf(FILE * stream,const char * format, va_list arg)
exponent). */
num_leading_digits = get_num_leading_digits(v,radix);
SHOWVALUE(num_leading_digits);
v /= pow(radix,(double)num_leading_digits);
for(i = 0 ; (max_digits != 0) && (i < num_leading_digits) && (output_buffer < buffer_stop) ; i++)

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*
* $Id: stdlib_strtod.c,v 1.5 2005-05-08 08:51:29 obarthel Exp $
* $Id: stdlib_strtod.c,v 1.6 2005-05-08 11:27:26 obarthel Exp $
*
* :ts=4
*
@ -123,17 +123,23 @@ 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 = (union ieee_double *)&sum;
union ieee_double x;
SHOWMSG("infinity");
str += strlen(str);
/* Exponent = 2047 and fraction = 0.0 */
x->raw[0] = 0x7ff00000;
x->raw[1] = 0x00000000;
x.raw[0] = 0x7ff00000;
x.raw[1] = 0x00000000;
sum = x.value;
}
else if (strncasecmp(str,"nan",3) == SAME && (str[3] == '(' || str[3] == '\0'))
{
union ieee_double * x = (union ieee_double *)&sum;
union ieee_double x;
SHOWMSG("not a number");
str += 3;
@ -148,8 +154,10 @@ strtod(const char *str, char ** ptr)
}
/* Exponent = 2047 and fraction != 0.0 */
x->raw[0] = 0x7ff00000;
x->raw[1] = 0x00000001;
x.raw[0] = 0x7ff00000;
x.raw[1] = 0x00000001;
sum = x.value;
}
else
{
@ -272,12 +280,15 @@ strtod(const char *str, char ** ptr)
int exponent_is_negative;
int new_exponent;
int exponent = 0;
int exponent_radix;
/* If we are processing a hexadecimal encoded
floating point number, switch to a binary
exponent. */
if(radix == 16)
radix = 2;
exponent_radix = 2;
else
exponent_radix = 10;
/* Skip the indicator. */
str++;
@ -302,16 +313,16 @@ strtod(const char *str, char ** ptr)
if('0' <= c && c <= '9')
c -= '0';
else
c = radix;
c = exponent_radix;
if(c >= radix)
if(c >= exponent_radix)
break;
str++;
if(error == 0)
{
new_exponent = (radix * exponent) + c;
new_exponent = (exponent_radix * exponent) + c;
if(new_exponent < exponent) /* overflow? */
error = ERANGE;
else

View File

@ -1,5 +1,5 @@
/*
* $Id: stdlib_strtof.c,v 1.3 2005-05-08 08:51:29 obarthel Exp $
* $Id: stdlib_strtof.c,v 1.4 2005-05-08 11:27:26 obarthel Exp $
*
* :ts=4
*
@ -123,16 +123,22 @@ 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 = (union ieee_single *)&sum;
union ieee_single x;
SHOWMSG("infinity");
str += strlen(str);
/* Exponent = 255 and fraction = 0.0 */
x->raw[0] = 0x7f800000;
x.raw[0] = 0x7f800000;
sum = x.value;
}
else if (strncasecmp(str,"nan",3) == SAME && (str[3] == '(' || str[3] == '\0'))
{
union ieee_single * x = (union ieee_single *)&sum;
union ieee_single x;
SHOWMSG("not a number");
str += 3;
@ -147,7 +153,9 @@ strtof(const char *str, char ** ptr)
}
/* Exponent = 255 and fraction != 0.0 */
x->raw[0] = 0x7f800001;
x.raw[0] = 0x7f800001;
sum = x.value;
}
else
{
@ -270,12 +278,15 @@ strtof(const char *str, char ** ptr)
int exponent_is_negative;
int new_exponent;
int exponent = 0;
int exponent_radix;
/* If we are processing a hexadecimal encoded
floating point number, switch to a binary
exponent. */
if(radix == 16)
radix = 2;
exponent_radix = 2;
else
exponent_radix = 10;
/* Skip the indicator. */
str++;
@ -300,16 +311,16 @@ strtof(const char *str, char ** ptr)
if('0' <= c && c <= '9')
c -= '0';
else
c = radix;
c = exponent_radix;
if(c >= radix)
if(c >= exponent_radix)
break;
str++;
if(error == 0)
{
new_exponent = (radix * exponent) + c;
new_exponent = (exponent_radix * exponent) + c;
if(new_exponent < exponent) /* overflow? */
error = ERANGE;
else

View File

@ -1,5 +1,5 @@
/*
* $Id: time_strftime.c,v 1.12 2005-05-07 14:03:08 obarthel Exp $
* $Id: time_strftime.c,v 1.13 2005-05-08 11:27:26 obarthel Exp $
*
* :ts=4
*
@ -113,7 +113,9 @@ julian_day(int day,int month,int year)
y = year + 4800 - a;
m = month + 12 * a - 3;
result = day + (153 * m + 2) / 5 + 365 * y + (y/4) - (y/100) + (y/400) - 32045;
result = day + (153 * m + 2) / 5 + 365 * y + (y / 4) - (y / 100) + (y / 400) - 32045;
return(result);
}
STATIC int