|
| 1 | +/* |
| 2 | +** Author: zerico2005 (2024) |
| 3 | +** Project: quadmath_cpp |
| 4 | +** License: MIT License |
| 5 | +** A copy of the MIT License should be included with |
| 6 | +** this project. If not, see https://opensource.org/license/MIT |
| 7 | +*/ |
| 8 | + |
| 9 | +#ifndef QUADMATH_CPP_H |
| 10 | +#define QUADMATH_CPP_H |
| 11 | + |
| 12 | +//------------------------------------------------------------------------------ |
| 13 | +// <quadmath.h> overloads |
| 14 | +//------------------------------------------------------------------------------ |
| 15 | + |
| 16 | +#include <cmath> |
| 17 | +#include <quadmath.h> |
| 18 | + |
| 19 | +/* Classification */ |
| 20 | + |
| 21 | +inline bool signbit(__float128 x) { return (signbitq(x) != 0); } |
| 22 | +inline bool isfinite(__float128 x) { return (finiteq(x) != 0); } |
| 23 | +inline bool isinf(__float128 x) { return (isinfq(x) != 0); } |
| 24 | +inline bool isnan(__float128 x) { return (isnanq(x) != 0); } |
| 25 | +inline bool issignaling(__float128 x) { return (issignalingq(x) != 0); } |
| 26 | + |
| 27 | +/* Manipulation */ |
| 28 | + |
| 29 | +inline __float128 fabs(__float128 x) { return fabsq(x); } |
| 30 | +inline __float128 copysign(__float128 x, __float128 y) { return copysignq(x, y); } |
| 31 | +inline __float128 nextafter(__float128 x, __float128 y) { return nextafterq(x, y); } |
| 32 | + |
| 33 | +/* Float Exponents */ |
| 34 | + |
| 35 | +inline int ilogb(__float128 x) { return ilogbq(x); } |
| 36 | +inline __float128 frexp (__float128 x, int* exp) { return frexpq (x, exp); } |
| 37 | +inline __float128 ldexp (__float128 x, int exp) { return ldexpq (x, exp); } |
| 38 | +inline __float128 scalbn (__float128 x, int exp) { return scalbnq (x, exp); } |
| 39 | +inline __float128 scalbln(__float128 x, long exp) { return scalblnq(x, exp); } |
| 40 | + |
| 41 | +/* Arithmetic */ |
| 42 | + |
| 43 | +inline __float128 fmax(__float128 x, __float128 y) { return fmaxq(x, y); } |
| 44 | +inline __float128 fmin(__float128 x, __float128 y) { return fminq(x, y); } |
| 45 | +inline __float128 fdim(__float128 x, __float128 y) { return fdimq(x, y); } |
| 46 | +inline __float128 fma(__float128 x, __float128 y, __float128 z) { return fmaq(x, y, z); } |
| 47 | +inline __float128 sqrt(__float128 x) { return sqrtq(x); } |
| 48 | +inline __float128 cbrt(__float128 x) { return cbrtq(x); } |
| 49 | +inline __float128 hypot(__float128 x, __float128 y) { return hypotq(x, y); } |
| 50 | + |
| 51 | +/* Remainder and Modulus */ |
| 52 | + |
| 53 | +inline __float128 fmod(__float128 x, __float128 y) { return fmodq(x, y); } |
| 54 | +inline __float128 modf(__float128 x, __float128* int_part) { return modfq(x, int_part); } |
| 55 | +inline __float128 remainder(__float128 x, __float128 y) { return remainderq(x, y); } |
| 56 | +inline __float128 remquo(__float128 x, __float128 y, int* quo) { return remquoq(x, y, quo); } |
| 57 | + |
| 58 | +/* Rounding */ |
| 59 | + |
| 60 | +inline __float128 trunc(__float128 x) { return truncq(x); } |
| 61 | +inline __float128 floor(__float128 x) { return floorq(x); } |
| 62 | +inline __float128 ceil (__float128 x) { return ceilq (x); } |
| 63 | +inline __float128 rint (__float128 x) { return rintq (x); } |
| 64 | +inline __float128 round(__float128 x) { return roundq(x); } |
| 65 | +inline long lrint (__float128 x) { return lrintq (x); } |
| 66 | +inline long lround(__float128 x) { return lroundq(x); } |
| 67 | +inline long long llrint (__float128 x) { return llrintq (x); } |
| 68 | +inline long long llround(__float128 x) { return llroundq(x); } |
| 69 | +inline __float128 nearbyint(__float128 x) { return nearbyintq(x); } |
| 70 | + |
| 71 | +/* Logarithms and Exponents */ |
| 72 | + |
| 73 | +inline __float128 log (__float128 x) { return logq (x); } |
| 74 | +inline __float128 log1p(__float128 x) { return log1pq(x); } |
| 75 | +inline __float128 logb (__float128 x) { return logbq (x); } |
| 76 | +inline __float128 log2 (__float128 x) { return log2q (x); } |
| 77 | +inline __float128 log10(__float128 x) { return log10q(x); } |
| 78 | +inline __float128 exp (__float128 x) { return expq (x); } |
| 79 | +inline __float128 expm1(__float128 x) { return expm1q(x); } |
| 80 | +inline __float128 exp2 (__float128 x) { return exp2q (x); } |
| 81 | +inline __float128 pow(__float128 x, __float128 y) { return powq(x, y); } |
| 82 | + |
| 83 | +/* Trigonometry */ |
| 84 | + |
| 85 | +inline __float128 sin (__float128 x) { return sinq (x); } |
| 86 | +inline __float128 cos (__float128 x) { return cosq (x); } |
| 87 | +inline __float128 tan (__float128 x) { return tanq (x); } |
| 88 | +inline __float128 asin (__float128 x) { return asinq (x); } |
| 89 | +inline __float128 acos (__float128 x) { return acosq (x); } |
| 90 | +inline __float128 atan (__float128 x) { return atanq (x); } |
| 91 | +inline __float128 sinh(__float128 x) { return sinhq(x); } |
| 92 | +inline __float128 cosh(__float128 x) { return coshq(x); } |
| 93 | +inline __float128 tanh(__float128 x) { return tanhq(x); } |
| 94 | +inline __float128 asinh(__float128 x) { return asinhq(x); } |
| 95 | +inline __float128 acosh(__float128 x) { return acoshq(x); } |
| 96 | +inline __float128 atanh(__float128 x) { return atanhq(x); } |
| 97 | +inline __float128 atan2(__float128 y, __float128 x) { return atan2q(y, x); } |
| 98 | +inline void sincos(__float128 x, __float128* p_sin, __float128* p_cos) { sincosq(x, p_sin, p_cos); } |
| 99 | + |
| 100 | +/* Transcendental Functions */ |
| 101 | + |
| 102 | +inline __float128 erf (__float128 x) { return erfq (x); } |
| 103 | +inline __float128 erfc(__float128 x) { return erfcq(x); } |
| 104 | +inline __float128 lgamma(__float128 x) { return lgammaq(x); } |
| 105 | +inline __float128 tgamma(__float128 x) { return tgammaq(x); } |
| 106 | + |
| 107 | +//------------------------------------------------------------------------------ |
| 108 | +// C++11 <cmath> overloads |
| 109 | +//------------------------------------------------------------------------------ |
| 110 | + |
| 111 | +/* Manipulation */ |
| 112 | + |
| 113 | +inline __float128 nexttoward(__float128 x, long double y) { |
| 114 | + return nextafterq(x, static_cast<__float128>(y)); |
| 115 | +} |
| 116 | + |
| 117 | +/* Compairison */ |
| 118 | + |
| 119 | +inline bool isgreater(__float128 x, __float128 y) { |
| 120 | + return (x > y); |
| 121 | +} |
| 122 | +inline bool isgreaterequal(__float128 x, __float128 y) { |
| 123 | + return (x >= y); |
| 124 | +} |
| 125 | +inline bool isless(__float128 x, __float128 y) { |
| 126 | + return (x < y); |
| 127 | +} |
| 128 | +inline bool islessequal(__float128 x, __float128 y) { |
| 129 | + return (x <= y); |
| 130 | +} |
| 131 | +inline bool islessgreater(__float128 x, __float128 y) { |
| 132 | + return (x < y) || (x > y); |
| 133 | +} |
| 134 | + |
| 135 | +/* Classification */ |
| 136 | + |
| 137 | +inline bool isunordered(__float128 x, __float128 y) { |
| 138 | + return (isnanq(x) != 0) || (isnanq(y) != 0); |
| 139 | +} |
| 140 | + |
| 141 | +inline bool isnormal(__float128 x) { |
| 142 | + return (finiteq(x) != 0 && fabsq(x) >= FLT128_MIN); |
| 143 | +} |
| 144 | + |
| 145 | +inline int fpclassify(__float128 x) { |
| 146 | + return |
| 147 | + isinfq(x) ? FP_INFINITE : |
| 148 | + isnanq(x) ? FP_NAN : |
| 149 | + x == static_cast<__float128>(0.0) ? FP_ZERO : |
| 150 | + isnormal(x) ? FP_NORMAL : |
| 151 | + FP_SUBNORMAL; |
| 152 | +} |
| 153 | + |
| 154 | +//------------------------------------------------------------------------------ |
| 155 | +// Additional overloads |
| 156 | +//------------------------------------------------------------------------------ |
| 157 | + |
| 158 | +/** @brief calls `exp(x * M_LN10q)` */ |
| 159 | +inline __float128 exp10(__float128 x) { |
| 160 | + return expq(x * M_LN10q); |
| 161 | +} |
| 162 | + |
| 163 | +/** @brief calls `*p_sinh = sinhq(x); *p_cosh = coshq(x);` */ |
| 164 | +inline void sinhcosh(__float128 x, __float128* p_sinh, __float128* p_cosh) { |
| 165 | + *p_sinh = sinhq(x); |
| 166 | + *p_cosh = coshq(x); |
| 167 | +} |
| 168 | + |
| 169 | +#endif /* QUADMATH_CPP_H */ |
0 commit comments