Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <float.h> |
| 18 | #include <math.h> |
| 19 | |
| 20 | extern int __isinf(double); /* isinf.c */ |
| 21 | int (isinf)(double a1) { return __isinf(a1); } |
| 22 | |
Elliott Hughes | 241608e | 2013-12-18 16:06:52 -0800 | [diff] [blame] | 23 | int (isnanf)(float a1) { return __isnanf(a1); } |
| 24 | |
Calin Juravle | f723b70 | 2014-04-01 17:38:59 +0100 | [diff] [blame] | 25 | /* |
| 26 | * On LP64 sizeof(long double) > sizeof(double) so functions which fall back |
| 27 | * to their double variants lose precision. Emit a warning whenever something |
| 28 | * links against such functions. |
| 29 | * On LP32 sizeof(long double) == sizeof(double) so we don't need to warn. |
| 30 | */ |
| 31 | #ifdef __LP64__ |
| 32 | #define WARN_IMPRECISE(x) \ |
| 33 | __warn_references(x, # x " has lower than advertised precision"); |
| 34 | #else |
| 35 | #define WARN_IMPRECISE(x) |
| 36 | #endif //__LP64__ |
| 37 | |
| 38 | #define DECLARE_IMPRECISE(f) \ |
| 39 | long double f ## l(long double v) { return f(v); } \ |
| 40 | WARN_IMPRECISE(x) |
| 41 | |
| 42 | DECLARE_IMPRECISE(cosh); |
| 43 | DECLARE_IMPRECISE(erfc); |
| 44 | DECLARE_IMPRECISE(erf); |
| 45 | DECLARE_IMPRECISE(lgamma); |
| 46 | DECLARE_IMPRECISE(sinh); |
| 47 | DECLARE_IMPRECISE(tanh); |
| 48 | DECLARE_IMPRECISE(tgamma); |
| 49 | DECLARE_IMPRECISE(significand); |
| 50 | |
Calin Juravle | 4d77c11 | 2014-03-14 17:56:46 +0000 | [diff] [blame] | 51 | long double powl(long double a1, long double a2) { return pow(a1, a2); } |
Calin Juravle | f723b70 | 2014-04-01 17:38:59 +0100 | [diff] [blame] | 52 | WARN_IMPRECISE(powl) |
Calin Juravle | 4d77c11 | 2014-03-14 17:56:46 +0000 | [diff] [blame] | 53 | |
| 54 | #ifndef __LP64__ |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 55 | /* |
| 56 | * The BSD "long double" functions are broken when sizeof(long double) == sizeof(double). |
| 57 | * Android works around those cases by replacing the broken functions with our own trivial stubs |
| 58 | * that call the regular "double" function. |
| 59 | */ |
| 60 | |
| 61 | int __fpclassifyl(long double a1) { return __fpclassifyd(a1); } |
| 62 | int __isfinitel(long double a1) { return __isfinite(a1); } |
| 63 | int __isinfl(long double a1) { return __isinf(a1); } |
Elliott Hughes | 28ddd91 | 2013-12-19 17:13:56 -0800 | [diff] [blame] | 64 | int __isnanl(long double a1) { return (isnan)(a1); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 65 | int __isnormall(long double a1) { return __isnormal(a1); } |
| 66 | int __signbitl(long double a1) { return __signbit(a1); } |
| 67 | |
| 68 | long double acoshl(long double a1) { return acosh(a1); } |
Elliott Hughes | 241608e | 2013-12-18 16:06:52 -0800 | [diff] [blame] | 69 | long double acosl(long double a1) { return acos(a1); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 70 | long double asinhl(long double a1) { return asinh(a1); } |
Elliott Hughes | 241608e | 2013-12-18 16:06:52 -0800 | [diff] [blame] | 71 | long double asinl(long double a1) { return asin(a1); } |
| 72 | long double atan2l(long double a1, long double a2) { return atan2(a1, a2); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 73 | long double atanhl(long double a1) { return atanh(a1); } |
Elliott Hughes | 241608e | 2013-12-18 16:06:52 -0800 | [diff] [blame] | 74 | long double atanl(long double a1) { return atan(a1); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 75 | long double cbrtl(long double a1) { return cbrt(a1); } |
Elliott Hughes | 241608e | 2013-12-18 16:06:52 -0800 | [diff] [blame] | 76 | long double ceill(long double a1) { return ceil(a1); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 77 | long double copysignl(long double a1, long double a2) { return copysign(a1, a2); } |
Calin Juravle | 4d77c11 | 2014-03-14 17:56:46 +0000 | [diff] [blame] | 78 | |
Elliott Hughes | 170dbe2 | 2013-02-07 17:45:11 -0800 | [diff] [blame] | 79 | long double cosl(long double a1) { return cos(a1); } |
Calin Juravle | 4d77c11 | 2014-03-14 17:56:46 +0000 | [diff] [blame] | 80 | |
Elliott Hughes | 241608e | 2013-12-18 16:06:52 -0800 | [diff] [blame] | 81 | long double exp2l(long double a1) { return exp2(a1); } |
| 82 | long double expl(long double a1) { return exp(a1); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 83 | long double expm1l(long double a1) { return expm1(a1); } |
| 84 | long double fabsl(long double a1) { return fabs(a1); } |
Elliott Hughes | 241608e | 2013-12-18 16:06:52 -0800 | [diff] [blame] | 85 | long double floorl(long double a1) { return floor(a1); } |
| 86 | long double fmal(long double a1, long double a2, long double a3) { return fma(a1, a2, a3); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 87 | long double fmaxl(long double a1, long double a2) { return fmax(a1, a2); } |
| 88 | long double fmodl(long double a1, long double a2) { return fmod(a1, a2); } |
| 89 | long double fminl(long double a1, long double a2) { return fmin(a1, a2); } |
Elliott Hughes | 241608e | 2013-12-18 16:06:52 -0800 | [diff] [blame] | 90 | long double frexpl(long double a1, int* a2) { return frexp(a1, a2); } |
| 91 | long double hypotl(long double a1, long double a2) { return hypot(a1, a2); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 92 | int ilogbl(long double a1) { return ilogb(a1); } |
Elliott Hughes | 241608e | 2013-12-18 16:06:52 -0800 | [diff] [blame] | 93 | long double ldexpl(long double a1, int a2) { return ldexp(a1, a2); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 94 | long long llrintl(long double a1) { return llrint(a1); } |
| 95 | long double log10l(long double a1) { return log10(a1); } |
| 96 | long double log1pl(long double a1) { return log1p(a1); } |
| 97 | long double log2l(long double a1) { return log2(a1); } |
Elliott Hughes | 926a307 | 2013-02-06 16:07:54 -0800 | [diff] [blame] | 98 | long double logbl(long double a1) { return logb(a1); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 99 | long double logl(long double a1) { return log(a1); } |
| 100 | long lrintl(long double a1) { return lrint(a1); } |
| 101 | long long llroundl(long double a1) { return llround(a1); } |
| 102 | long lroundl(long double a1) { return lround(a1); } |
Calin Juravle | 4d77c11 | 2014-03-14 17:56:46 +0000 | [diff] [blame] | 103 | long double modfl(long double a1, long double* a2) { double i; double f = modf(a1, &i); *a2 = i; return f; } |
Elliott Hughes | 241608e | 2013-12-18 16:06:52 -0800 | [diff] [blame] | 104 | long double nanl(const char* a1) { return nan(a1); } |
| 105 | long double nextafterl(long double a1, long double a2) { return nextafter(a1, a2); } |
Elliott Hughes | 241608e | 2013-12-18 16:06:52 -0800 | [diff] [blame] | 106 | long double remainderl(long double a1, long double a2) { return remainder(a1, a2); } |
| 107 | long double remquol(long double a1, long double a2, int* a3) { return remquo(a1, a2, a3); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 108 | long double rintl(long double a1) { return rint(a1); } |
| 109 | long double roundl(long double a1) { return round(a1); } |
| 110 | long double scalbnl(long double a1, int a2) { return scalbn(a1, a2); } |
Elliott Hughes | 170dbe2 | 2013-02-07 17:45:11 -0800 | [diff] [blame] | 111 | long double sinl(long double a1) { return sin(a1); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 112 | long double sqrtl(long double a1) { return sqrt(a1); } |
Elliott Hughes | 170dbe2 | 2013-02-07 17:45:11 -0800 | [diff] [blame] | 113 | long double tanl(long double a1) { return tan(a1); } |
Elliott Hughes | 241608e | 2013-12-18 16:06:52 -0800 | [diff] [blame] | 114 | long double truncl(long double a1) { return trunc(a1); } |
Calin Juravle | 4d77c11 | 2014-03-14 17:56:46 +0000 | [diff] [blame] | 115 | |
| 116 | #endif // __LP64__ |