Fix #115 by fixing the math.h and cmath includes.

This commit is contained in:
Jacob Young
2017-09-12 02:21:22 -04:00
committed by Ecco
parent e05033cf6e
commit da1e66e798
41 changed files with 497 additions and 140 deletions

View File

@@ -140,6 +140,7 @@ tests += $(addprefix liba/test/, \
double.c \
ieee754.c \
long.c \
math.c \
setjmp.c \
stddef.c \
stdint.c \

View File

@@ -6,13 +6,28 @@
LIBA_BEGIN_DECLS
#define NAN (0.0f/0.0f)
typedef float float_t;
typedef double double_t;
#define M_E 2.71828182845904524
#define M_LOG2E 1.44269504088896341
#define M_LOG10E 0.43429448190325183
#define M_LN2 0.69314718055994531
#define M_LN10 2.30258509299404568
#define M_PI 3.14159265358979324
#define M_PI_2 1.57079632679489662
#define M_PI_4 0.78539816339744831
#define M_1_PI 0.31830988618379067
#define M_2_PI 0.63661977236758134
#define M_2_SQRTPI 1.12837916709551257
#define M_SQRT2 1.41421356237309505
#define M_SQRT1_2 0.70710678118654752
#define MAXFLOAT FLT_MAX
#define HUGE_VAL __builtin_huge_val()
#define HUGE_VALF __builtin_huge_valf()
#define INFINITY __builtin_inff()
#define M_E 2.71828182845904523536028747135266250
#define M_PI 3.14159265358979323846264338327950288
#define M_PI_2 1.57079632679489661923132169163975144
#define M_PI_4 0.78539816339744830961566084581987572
#define M_SQRT2 1.41421356237309504880168872420969808
#define NAN __builtin_nanf("")
#define FP_INFINITE 0x01
#define FP_NAN 0x02
@@ -20,21 +35,11 @@ LIBA_BEGIN_DECLS
#define FP_SUBNORMAL 0x08
#define FP_ZERO 0x10
/* The C99 standard requires isinf and isnan to be defined as macros that can
* handle arbitrary precision float numbers. The names of the functions called
* by those macros (depending on the argument size) are not standardized though.
* We're chosing isinff/isnanf for single-precision functions, and isinfd/isnand
* for double-precision functions. */
int isinff(float x);
int isinfd(double d);
#define isinf(x) (sizeof(x) == sizeof(float) ? isinff(x) : isinfd(x))
int isnanf(float x);
int isnand(double x);
#define isnan(x) (sizeof(x) == sizeof(float) ? isnanf(x) : isnand(x))
int __fpclassifyf(float x);
int __fpclassify(double x);
#define fpclassify(x) ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) : __fpclassify(x))
#define fpclassify(x) __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
#define isfinite(x) __builtin_isfinite(x)
#define isnormal(x) __builtin_isnormal(x)
#define isnan(x) __builtin_isnan(x)
#define isinf(x) __builtin_isinf(x)
float acosf(float x);
float acoshf(float x);
@@ -68,6 +73,38 @@ float sqrtf(float x);
float tanf(float x);
float tanhf(float x);
#define acosf(x) __builtin_acosf(x)
#define acoshf(x) __builtin_acoshf(x)
#define asinf(x) __builtin_asinf(x)
#define asinhf(x) __builtin_asinhf(x)
#define atanf(x) __builtin_atanf(x)
#define atan2f(y, x) __builtin_atan2f(y, x)
#define atanhf(x) __builtin_atanhf(x)
#define ceilf(x) __builtin_ceilf(x)
#define copysignf(x, y) __builtin_copysignf(x, y)
#define cosf(x) __builtin_cosf(x)
#define coshf(x) __builtin_coshf(x)
#define expf(x) __builtin_expf(x)
#define expm1f(x) __builtin_expm1f(x)
#define fabsf(x) __builtin_fabsf(x)
#define floorf(x) __builtin_floorf(x)
#define fmodf(x, y) __builtin_fmodf(x, y)
#define lgammaf(x) __builtin_lgammaf(x)
#define lgammaf_r(x, signgamp) __builtin_lgammaf_r(x, signgamp)
#define log1pf(x) __builtin_log1pf(x)
#define log10f(x) __builtin_log10f(x)
#define logf(x) __builtin_logf(x)
#define nanf(s) __builtin_nanf(s)
#define nearbyintf(x) __builtin_nearbyintf(x)
#define powf(x, y) __builtin_powf(x, y)
#define roundf(x) __builtin_roundf(x)
#define scalbnf(x, n) __builtin_scalbnf(x, n)
#define sinf(x) __builtin_sinf(x)
#define sinhf(x) __builtin_sinhf(x)
#define sqrtf(x) __builtin_sqrtf(x)
#define tanf(x) __builtin_tanf(x)
#define tanhf(x) __builtin_tanhf(x)
double acos(double x);
double acosh(double x);
double asin(double x);
@@ -96,6 +133,36 @@ double sqrt(double x);
double tan(double x);
double tanh(double x);
#define acos(x) __builtin_acos(x)
#define acosh(x) __builtin_acosh(x)
#define asin(x) __builtin_asin(x)
#define asinh(x) __builtin_asinh(x)
#define atan(x) __builtin_atan(x)
#define atanh(x) __builtin_atanh(x)
#define ceil(x) __builtin_ceil(x)
#define copysign(x, y) __builtin_copysign(x, y)
#define cos(x) __builtin_cos(x)
#define cosh(x) __builtin_cosh(x)
#define exp(x) __builtin_exp(x)
#define expm1(x) __builtin_expm1(x)
#define fabs(x) __builtin_fabs(x)
#define floor(x) __builtin_floor(x)
#define lgamma(x) __builtin_lgamma(x)
#define lgamma_r(x, signgamp) __builtin_lgamma_r(x, signgamp)
#define log1p(x) __builtin_log1p(x)
#define log10(x) __builtin_log10(x)
#define log(x) __builtin_log(x)
#define pow(x, y) __builtin_pow(x, y)
#define round(x) __builtin_round(x)
#define scalbn(x, n) __builtin_scalbn(x, n)
#define sin(x) __builtin_sin(x)
#define sinh(x) __builtin_sinh(x)
#define sqrt(x) __builtin_sqrt(x)
#define tan(x) __builtin_tan(x)
#define tanh(x) __builtin_tanh(x)
extern int signgam;
LIBA_END_DECLS
#endif

View File

@@ -42,6 +42,10 @@ int __aeabi_dcmplt(aeabi_double_t a, aeabi_double_t b) {
return f64_lt(f64(a), f64(b));
}
int __aeabi_dcmpun(aeabi_double_t a, aeabi_double_t b) {
return !f64_eq(f64(a), f64(a)) || !f64_eq(f64(b), f64(b));
}
// Arithmetics
aeabi_double_t __aeabi_dadd(aeabi_double_t a, aeabi_double_t b) {

210
liba/test/math.c Normal file
View File

@@ -0,0 +1,210 @@
// This file tests that each math fuction links.
#include <math.h>
int test_fpclassifyf(float x) {
return fpclassify(x);
}
int test_isfinitef(float x) {
return isfinite(x);
}
int test_isnormalf(float x) {
return isnormal(x);
}
int test_isnanf(float x) {
return isnan(x);
}
int test_isinff(float x) {
return isinf(x);
}
float test_acosf(float x) {
return acosf(x);
}
float test_acoshf(float x) {
return acoshf(x);
}
float test_asinf(float x) {
return asinf(x);
}
float test_asinhf(float x) {
return asinhf(x);
}
float test_atanf(float x) {
return atanf(x);
}
float test_atan2f(float y, float x) {
return atan2f(y, x);
}
float test_atanhf(float x) {
return atanhf(x);
}
float test_ceilf(float x) {
return ceilf(x);
}
float test_copysignf(float x, float y) {
return copysignf(x, y);
}
float test_cosf(float x) {
return cosf(x);
}
float test_coshf(float x) {
return coshf(x);
}
float test_expf(float x) {
return expf(x);
}
float test_expm1f(float x) {
return expm1f(x);
}
float test_fabsf(float x) {
return fabsf(x);
}
float test_floorf(float x) {
return floorf(x);
}
float test_fmodf(float x, float y) {
return fmodf(x, y);
}
float test_lgammaf(float x) {
return lgammaf(x);
}
float test_lgammaf_r(float x, int *signgamp) {
return lgammaf_r(x, signgamp);
}
float test_log1pf(float x) {
return log1pf(x);
}
float test_log10f(float x) {
return log10f(x);
}
float test_logf(float x) {
return logf(x);
}
float test_nanf(const char *s) {
return nanf(s);
}
float test_nearbyintf(float x) {
return nearbyintf(x);
}
float test_powf(float x, float y) {
return powf(x, y);
}
float test_roundf(float x) {
return roundf(x);
}
float test_scalbnf(float x, int n) {
return scalbnf(x, n);
}
float test_sinf(float x) {
return sinf(x);
}
float test_sinhf(float x) {
return sinhf(x);
}
float test_sqrtf(float x) {
return sqrtf(x);
}
float test_tanf(float x) {
return tanf(x);
}
float test_tanhf(float x) {
return tanhf(x);
}
int test_fpclassify(double x) {
return fpclassify(x);
}
int test_isfinite(double x) {
return isfinite(x);
}
int test_isnormal(double x) {
return isnormal(x);
}
int test_isnan(double x) {
return isnan(x);
}
int test_isinf(double x) {
return isinf(x);
}
double test_acos(double x) {
return acos(x);
}
double test_acosh(double x) {
return acosh(x);
}
double test_asin(double x) {
return asin(x);
}
double test_asinh(double x) {
return asinh(x);
}
double test_atan(double x) {
return atan(x);
}
double test_atanh(double x) {
return atanh(x);
}
double test_ceil(double x) {
return ceil(x);
}
double test_copysign(double x, double y) {
return copysign(x, y);
}
double test_cos(double x) {
return cos(x);
}
double test_cosh(double x) {
return cosh(x);
}
double test_exp(double x) {
return exp(x);
}
double test_expm1(double x) {
return expm1(x);
}
double test_fabs(double x) {
return fabs(x);
}
double test_floor(double x) {
return floor(x);
}
double test_lgamma(double x) {
return lgamma(x);
}
double test_lgamma_r(double x, int *signgamp) {
return lgamma_r(x, signgamp);
}
double test_log1p(double x) {
return log1p(x);
}
double test_log10(double x) {
return log10(x);
}
double test_log(double x) {
return log(x);
}
double test_pow(double x, double y) {
return pow(x, y);
}
double test_round(double x) {
return round(x);
}
double test_scalbn(double x, int n) {
return scalbn(x, n);
}
double test_sin(double x) {
return sin(x);
}
double test_sinh(double x) {
return sinh(x);
}
double test_sqrt(double x) {
return sqrt(x);
}
double test_tan(double x) {
return tan(x);
}
double test_tanh(double x) {
return tanh(x);
}