Floating point support functions
This commit is contained in:
@@ -9,6 +9,7 @@ libc_FILES=" \
|
||||
atan.c \
|
||||
atan2.c \
|
||||
ceil.c \
|
||||
compare.c \
|
||||
exp.c \
|
||||
fabs.c \
|
||||
floor.c \
|
||||
|
||||
39
lib/math/compare.c
Normal file
39
lib/math/compare.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
/* functions missing here are architecture-specific and are in i386/float */
|
||||
|
||||
int isfinite(double x)
|
||||
{
|
||||
/* return value based on classification */
|
||||
switch (fpclassify(x))
|
||||
{
|
||||
case FP_INFINITE:
|
||||
case FP_NAN:
|
||||
return 0;
|
||||
|
||||
case FP_NORMAL:
|
||||
case FP_SUBNORMAL:
|
||||
case FP_ZERO:
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* if we get here, fpclassify is buggy */
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int isinf(double x)
|
||||
{
|
||||
return fpclassify(x) == FP_INFINITE;
|
||||
}
|
||||
|
||||
int isnan(double x)
|
||||
{
|
||||
return fpclassify(x) == FP_NAN;
|
||||
}
|
||||
|
||||
int isnormal(double x)
|
||||
{
|
||||
return fpclassify(x) == FP_NORMAL;
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <math.h>
|
||||
|
||||
double
|
||||
__huge_val(void)
|
||||
__infinity(void)
|
||||
{
|
||||
#if (CHIP == INTEL)
|
||||
static unsigned char ieee_infinity[] = {
|
||||
@@ -21,3 +21,18 @@ __huge_val(void)
|
||||
return 1.0e+1000; /* This will generate a warning */
|
||||
#endif
|
||||
}
|
||||
|
||||
double
|
||||
__qnan(void)
|
||||
{
|
||||
#if (CHIP == INTEL)
|
||||
static unsigned char ieee_qnan[] = {
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f };
|
||||
|
||||
assert(sizeof(double) == sizeof(ieee_qnan));
|
||||
return *(double *) ieee_qnan;
|
||||
#else
|
||||
#error QNaN not defined on this architecture
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#define __IsNan isnan
|
||||
|
||||
/* some constants (Hart & Cheney) */
|
||||
#define M_PI 3.14159265358979323846264338327950288
|
||||
#define M_2PI 6.28318530717958647692528676655900576
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <errno.h>
|
||||
#include "localmath.h"
|
||||
|
||||
#define NITER 5
|
||||
|
||||
|
||||
Reference in New Issue
Block a user