Some rough floating point macros!
This commit is contained in:
parent
2ada975628
commit
ef5fd0562f
4 changed files with 173 additions and 3 deletions
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* This header is a part of the FENIX C Library and is free software.
|
||||
* You can redistribute and/or modify it subject to the terms of the
|
||||
* Clumsy Wolf Public License v4. For more details, see the file COPYING.
|
||||
* Clumsy Wolf Public License v5. For more details, see the file COPYING.
|
||||
*
|
||||
* The FENIX C Library is distributed WITH NO WARRANTY WHATSOEVER. See
|
||||
* The CWPL for more details.
|
||||
|
@ -12,6 +12,8 @@
|
|||
#ifndef _MATH_H
|
||||
#define _MATH_H
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#if FLT_EVAL_METHOD == 1
|
||||
typedef double float_t;
|
||||
typedef double double_t;
|
||||
|
@ -23,6 +25,44 @@ typedef float float_t;
|
|||
typedef double double_t;
|
||||
#endif
|
||||
|
||||
/* Both of these are basically lifted from musl. */
|
||||
#define INFINITY (1e5000)
|
||||
#define NAN (0.0f / 0.0f)
|
||||
|
||||
#define FP_INFINITE 1
|
||||
#define FP_NAN 2
|
||||
#define FP_NORMAL 3
|
||||
#define FP_SUBNORMAL 4
|
||||
#define FP_ZERO 0
|
||||
|
||||
int __fpclassifyd(double x);
|
||||
int __fpclassifyf(float x);
|
||||
int __fpclassifyl(long double x);
|
||||
|
||||
/* We're just gonna use the approach in the C standard here */
|
||||
#define fpclassify(x) ((sizeof(x) == sizeof(float)) ? __fpclassifyf(x) : \
|
||||
(sizeof(x) == sizeof(double)) ? __fpclassifyd(x) : \
|
||||
__fpclassifyl(x))
|
||||
|
||||
#define isfinite(x) ((fpclassify(x) != FP_INFINITE) && (fpclassify(x) != FP_NAN))
|
||||
#define isinf(x) (fpclassify(x) == FP_INFINITE)
|
||||
#define isnan(x) (fpclassify(x) == FP_NAN)
|
||||
#define isnormal(x) (fpclassify(x) == FP_NORMAL)
|
||||
|
||||
int __signbitd(double x);
|
||||
int __signbitf(float x);
|
||||
int __signbitl(long double x);
|
||||
|
||||
/*
|
||||
In theory, I could just use (x < 0 || x == -0.0f), but would that work for
|
||||
infinity and NaN? I feel like no. So fuck it. We'll just write some small
|
||||
functions to pull the sign bit straight from the number.
|
||||
-Kat
|
||||
*/
|
||||
#define signbit(x) ((sizeof(x) == sizeof(float)) ? __signbitf(x) : \
|
||||
(sizeof(x) == sizeof(double)) ? __signbitd(x) : \
|
||||
__signbitl(x))
|
||||
|
||||
#define M_E 2.718281828
|
||||
#define M_PI 3.14159265
|
||||
#define PI 3.14159265
|
||||
|
@ -40,7 +80,10 @@ typedef double double_t;
|
|||
|
||||
#define MATH_ERRNO 1
|
||||
#define MATH_ERREXCEPT 2
|
||||
#define math_errhandling (int) (MATH_ERRNO | MATH_ERREXCEPT)
|
||||
#define math_errhandling MATH_ERRNO
|
||||
|
||||
#define FP_ILOGB0 INT_MIN
|
||||
#define FP_ILOGBNAN INT_MAX
|
||||
|
||||
double acos(double);
|
||||
float acosf(float);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue