2020-11-18 09:41:58 +00:00
|
|
|
/*
|
|
|
|
* <math.h> - mathematics
|
|
|
|
*
|
|
|
|
* 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
|
2022-05-28 16:15:26 +00:00
|
|
|
* Clumsy Wolf Public License v5. For more details, see the file COPYING.
|
2020-11-18 09:41:58 +00:00
|
|
|
*
|
|
|
|
* The FENIX C Library is distributed WITH NO WARRANTY WHATSOEVER. See
|
|
|
|
* The CWPL for more details.
|
|
|
|
*/
|
|
|
|
|
2020-02-12 05:23:27 +00:00
|
|
|
#ifndef _MATH_H
|
|
|
|
#define _MATH_H
|
|
|
|
|
2022-05-28 16:15:26 +00:00
|
|
|
#include <limits.h>
|
|
|
|
|
2020-02-12 05:23:27 +00:00
|
|
|
#if FLT_EVAL_METHOD == 1
|
2020-11-18 09:41:58 +00:00
|
|
|
typedef double float_t;
|
|
|
|
typedef double double_t;
|
2020-02-12 05:23:27 +00:00
|
|
|
#elseif FLT_EVAL_METHOD == 2
|
2020-11-18 09:41:58 +00:00
|
|
|
typedef long double float_t;
|
|
|
|
typedef long double double_t;
|
2020-02-12 05:23:27 +00:00
|
|
|
#else
|
2020-11-18 09:41:58 +00:00
|
|
|
typedef float float_t;
|
|
|
|
typedef double double_t;
|
2020-02-12 05:23:27 +00:00
|
|
|
#endif
|
|
|
|
|
2022-05-28 16:15:26 +00:00
|
|
|
/* Both of these are basically lifted from musl. */
|
|
|
|
#define INFINITY (1e5000)
|
|
|
|
#define NAN (0.0f / 0.0f)
|
|
|
|
|
2022-05-28 16:33:37 +00:00
|
|
|
/* iirc, this is how musl does it. */
|
|
|
|
#define HUGE_VAL INFINITY
|
|
|
|
#define HUGE_VALF ((float) INFINITY)
|
|
|
|
#define HUGE_VALL ((long double) INFINITY)
|
|
|
|
|
|
|
|
#define M_E 2.718281828
|
|
|
|
#define M_PI 3.14159265
|
|
|
|
#define PI 3.14159265
|
|
|
|
#define M_PI_2 1.5707963268
|
|
|
|
#define M_PI_4 0.7853981634
|
|
|
|
#define M_1_PI 0.318309886184
|
|
|
|
#define M_2_PI 0.636619772368
|
|
|
|
#define M_2_SQRTPI 1.1283791671
|
|
|
|
#define M_SQRT2 1.41421856237
|
|
|
|
#define M_SQRT1_2 0.707106781187
|
|
|
|
#define M_LOG2E 1.44269504089
|
|
|
|
#define M_LOG10E 0.4342944819
|
|
|
|
#define M_LN2 0.69314718056
|
|
|
|
#define M_LN10 2.302585093
|
|
|
|
|
|
|
|
#define MATH_ERRNO 1
|
|
|
|
#define MATH_ERREXCEPT 2
|
|
|
|
#define math_errhandling MATH_ERRNO
|
|
|
|
|
|
|
|
#define FP_ILOGB0 INT_MIN
|
|
|
|
#define FP_ILOGBNAN INT_MAX
|
|
|
|
|
2022-05-28 16:15:26 +00:00
|
|
|
#define FP_INFINITE 1
|
|
|
|
#define FP_NAN 2
|
|
|
|
#define FP_NORMAL 3
|
|
|
|
#define FP_SUBNORMAL 4
|
|
|
|
#define FP_ZERO 0
|
|
|
|
|
2022-05-28 16:33:37 +00:00
|
|
|
/* Classification Macros 7.12.3 */
|
|
|
|
|
2022-05-28 16:15:26 +00:00
|
|
|
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))
|
|
|
|
|
2022-05-28 16:33:37 +00:00
|
|
|
/* Trigonometric Functions (ISO C Std. 7.12.4) */
|
2020-12-01 23:30:40 +00:00
|
|
|
|
2020-02-12 05:23:27 +00:00
|
|
|
double acos(double);
|
|
|
|
float acosf(float);
|
|
|
|
long double acosl(long double);
|
|
|
|
|
|
|
|
double asin(double);
|
|
|
|
float asinf(float);
|
|
|
|
long double asinl(long double);
|
|
|
|
|
|
|
|
double atan(double);
|
|
|
|
float atanf(float);
|
|
|
|
long double atanl(long double);
|
|
|
|
|
|
|
|
double atan2(double);
|
|
|
|
float atan2f(float);
|
|
|
|
long double atan2l(long double);
|
|
|
|
|
|
|
|
double cos(double);
|
|
|
|
float cosf(float);
|
|
|
|
long double cosl(long double);
|
|
|
|
|
|
|
|
double sin(double);
|
|
|
|
float sinf(float);
|
|
|
|
long double sinl(long double);
|
|
|
|
|
|
|
|
double tan(double);
|
|
|
|
float tanf(float);
|
|
|
|
long double tanl(long double);
|
|
|
|
|
2022-05-28 16:33:37 +00:00
|
|
|
/* Hyperbolic Functions (ISO C Std. 7.12.5) */
|
|
|
|
|
2020-02-12 05:23:27 +00:00
|
|
|
double acosh(double);
|
|
|
|
float acoshf(float);
|
|
|
|
long double acoshl(long double);
|
|
|
|
|
|
|
|
double asinh(double);
|
|
|
|
float asinhf(float);
|
|
|
|
long double asinhl(long double);
|
|
|
|
|
|
|
|
double atanh(double);
|
|
|
|
float atanhf(float);
|
|
|
|
long double atanhl(long double);
|
|
|
|
|
|
|
|
double cosh(double);
|
|
|
|
float coshf(float);
|
|
|
|
long double coshl(long double);
|
|
|
|
|
|
|
|
double sinh(double);
|
|
|
|
float sinhf(float);
|
|
|
|
long double sinhl(long double);
|
|
|
|
|
|
|
|
double tanh(double);
|
|
|
|
float tanhf(float);
|
|
|
|
long double tanhl(long double);
|
|
|
|
|
2022-05-28 16:33:37 +00:00
|
|
|
/* Exponential and Logarithmic Functions (ISO C Std. 7.12.6) */
|
|
|
|
|
2020-02-12 05:23:27 +00:00
|
|
|
double exp(double);
|
|
|
|
float expf(float);
|
2022-05-28 16:33:37 +00:00
|
|
|
long double expl(long double);
|
2020-02-12 05:23:27 +00:00
|
|
|
|
|
|
|
double exp2(double);
|
|
|
|
float exp2f(float);
|
2022-05-28 16:33:37 +00:00
|
|
|
long double exp2l(long double);
|
2020-02-12 05:23:27 +00:00
|
|
|
|
|
|
|
double expm1(double);
|
|
|
|
float expm1f(float);
|
2022-05-28 16:33:37 +00:00
|
|
|
long double expm1l(long double);
|
2020-02-12 05:23:27 +00:00
|
|
|
|
|
|
|
double frexp(double, int *);
|
|
|
|
float frexpf(float, int *);
|
2022-05-28 16:33:37 +00:00
|
|
|
long double frexpl(long double, int *);
|
|
|
|
|
|
|
|
int ilogb(double);
|
|
|
|
int ilogbf(float);
|
|
|
|
int ilogbl(long double);
|
|
|
|
|
|
|
|
double ldexp(double, int);
|
|
|
|
float ldexpf(float, int);
|
|
|
|
long double ldexpl(long double, int);
|
|
|
|
|
|
|
|
double log(double);
|
|
|
|
float logf(float);
|
|
|
|
long double logl(long double);
|
|
|
|
|
|
|
|
double log10(double);
|
|
|
|
float log10f(float);
|
|
|
|
long double log10l(long double);
|
|
|
|
|
|
|
|
double log1p(double);
|
|
|
|
float log1pf(float);
|
|
|
|
long double log1pl(long double);
|
|
|
|
|
|
|
|
double log2(double);
|
|
|
|
float log2f(float);
|
|
|
|
long double log2l(long double);
|
|
|
|
|
|
|
|
double logb(double);
|
|
|
|
float logbf(float);
|
|
|
|
long double logbl(long double);
|
|
|
|
|
|
|
|
double modf(double, double *);
|
|
|
|
float modff(float, float *);
|
|
|
|
long double modfl(long double, long double *);
|
|
|
|
|
|
|
|
double scalbn(double, int);
|
|
|
|
float scalbnf(float, int);
|
|
|
|
long double scalbnl(long double, int);
|
|
|
|
|
|
|
|
double scalbln(double, long);
|
|
|
|
float scalblnf(float, long);
|
|
|
|
long double scalblnl(long double, long);
|
|
|
|
|
|
|
|
/* Power and Absolute Value Functions (ISO C Std. 7.12.7) */
|
2020-02-12 05:23:27 +00:00
|
|
|
|
2020-12-01 23:30:40 +00:00
|
|
|
double fabs(double);
|
|
|
|
float fabsf(float);
|
|
|
|
long double fabsl(long double);
|
|
|
|
|
2020-02-12 05:23:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
#endif
|