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 | |
Calin Juravle | f723b70 | 2014-04-01 17:38:59 +0100 | [diff] [blame] | 20 | /* |
| 21 | * On LP64 sizeof(long double) > sizeof(double) so functions which fall back |
| 22 | * to their double variants lose precision. Emit a warning whenever something |
| 23 | * links against such functions. |
| 24 | * On LP32 sizeof(long double) == sizeof(double) so we don't need to warn. |
| 25 | */ |
| 26 | #ifdef __LP64__ |
| 27 | #define WARN_IMPRECISE(x) \ |
| 28 | __warn_references(x, # x " has lower than advertised precision"); |
| 29 | #else |
| 30 | #define WARN_IMPRECISE(x) |
| 31 | #endif //__LP64__ |
| 32 | |
| 33 | #define DECLARE_IMPRECISE(f) \ |
| 34 | long double f ## l(long double v) { return f(v); } \ |
| 35 | WARN_IMPRECISE(x) |
| 36 | |
| 37 | DECLARE_IMPRECISE(cosh); |
| 38 | DECLARE_IMPRECISE(erfc); |
| 39 | DECLARE_IMPRECISE(erf); |
| 40 | DECLARE_IMPRECISE(lgamma); |
| 41 | DECLARE_IMPRECISE(sinh); |
| 42 | DECLARE_IMPRECISE(tanh); |
| 43 | DECLARE_IMPRECISE(tgamma); |
| 44 | DECLARE_IMPRECISE(significand); |
| 45 | |
Calin Juravle | 4d77c11 | 2014-03-14 17:56:46 +0000 | [diff] [blame] | 46 | 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] | 47 | WARN_IMPRECISE(powl) |
Calin Juravle | 4d77c11 | 2014-03-14 17:56:46 +0000 | [diff] [blame] | 48 | |
| 49 | #ifndef __LP64__ |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 50 | /* |
| 51 | * The BSD "long double" functions are broken when sizeof(long double) == sizeof(double). |
| 52 | * Android works around those cases by replacing the broken functions with our own trivial stubs |
| 53 | * that call the regular "double" function. |
| 54 | */ |
| 55 | |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 56 | int __isfinitel(long double a1) { return __isfinite(a1); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 57 | int __isnormall(long double a1) { return __isnormal(a1); } |
| 58 | int __signbitl(long double a1) { return __signbit(a1); } |
| 59 | |
| 60 | long double acoshl(long double a1) { return acosh(a1); } |
Elliott Hughes | 241608e | 2013-12-18 16:06:52 -0800 | [diff] [blame] | 61 | long double acosl(long double a1) { return acos(a1); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 62 | long double asinhl(long double a1) { return asinh(a1); } |
Elliott Hughes | 241608e | 2013-12-18 16:06:52 -0800 | [diff] [blame] | 63 | long double asinl(long double a1) { return asin(a1); } |
| 64 | 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] | 65 | long double atanhl(long double a1) { return atanh(a1); } |
Elliott Hughes | 241608e | 2013-12-18 16:06:52 -0800 | [diff] [blame] | 66 | long double atanl(long double a1) { return atan(a1); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 67 | long double cbrtl(long double a1) { return cbrt(a1); } |
Elliott Hughes | 241608e | 2013-12-18 16:06:52 -0800 | [diff] [blame] | 68 | long double ceill(long double a1) { return ceil(a1); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 69 | 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] | 70 | |
Elliott Hughes | 170dbe2 | 2013-02-07 17:45:11 -0800 | [diff] [blame] | 71 | long double cosl(long double a1) { return cos(a1); } |
Calin Juravle | 4d77c11 | 2014-03-14 17:56:46 +0000 | [diff] [blame] | 72 | |
Elliott Hughes | 241608e | 2013-12-18 16:06:52 -0800 | [diff] [blame] | 73 | long double exp2l(long double a1) { return exp2(a1); } |
| 74 | long double expl(long double a1) { return exp(a1); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 75 | long double expm1l(long double a1) { return expm1(a1); } |
| 76 | long double fabsl(long double a1) { return fabs(a1); } |
Elliott Hughes | 241608e | 2013-12-18 16:06:52 -0800 | [diff] [blame] | 77 | long double floorl(long double a1) { return floor(a1); } |
| 78 | 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] | 79 | long double fmaxl(long double a1, long double a2) { return fmax(a1, a2); } |
| 80 | long double fmodl(long double a1, long double a2) { return fmod(a1, a2); } |
| 81 | 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] | 82 | long double frexpl(long double a1, int* a2) { return frexp(a1, a2); } |
| 83 | 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] | 84 | int ilogbl(long double a1) { return ilogb(a1); } |
Elliott Hughes | 241608e | 2013-12-18 16:06:52 -0800 | [diff] [blame] | 85 | long double ldexpl(long double a1, int a2) { return ldexp(a1, a2); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 86 | long long llrintl(long double a1) { return llrint(a1); } |
| 87 | long double log10l(long double a1) { return log10(a1); } |
| 88 | long double log1pl(long double a1) { return log1p(a1); } |
| 89 | long double log2l(long double a1) { return log2(a1); } |
Elliott Hughes | 926a307 | 2013-02-06 16:07:54 -0800 | [diff] [blame] | 90 | long double logbl(long double a1) { return logb(a1); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 91 | long double logl(long double a1) { return log(a1); } |
| 92 | long lrintl(long double a1) { return lrint(a1); } |
| 93 | long long llroundl(long double a1) { return llround(a1); } |
| 94 | long lroundl(long double a1) { return lround(a1); } |
Calin Juravle | 4d77c11 | 2014-03-14 17:56:46 +0000 | [diff] [blame] | 95 | 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] | 96 | long double nanl(const char* a1) { return nan(a1); } |
| 97 | 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] | 98 | long double remainderl(long double a1, long double a2) { return remainder(a1, a2); } |
| 99 | 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] | 100 | long double rintl(long double a1) { return rint(a1); } |
| 101 | long double roundl(long double a1) { return round(a1); } |
| 102 | long double scalbnl(long double a1, int a2) { return scalbn(a1, a2); } |
Elliott Hughes | 170dbe2 | 2013-02-07 17:45:11 -0800 | [diff] [blame] | 103 | long double sinl(long double a1) { return sin(a1); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 104 | long double sqrtl(long double a1) { return sqrt(a1); } |
Elliott Hughes | 170dbe2 | 2013-02-07 17:45:11 -0800 | [diff] [blame] | 105 | long double tanl(long double a1) { return tan(a1); } |
Elliott Hughes | 241608e | 2013-12-18 16:06:52 -0800 | [diff] [blame] | 106 | long double truncl(long double a1) { return trunc(a1); } |
Calin Juravle | 4d77c11 | 2014-03-14 17:56:46 +0000 | [diff] [blame] | 107 | |
| 108 | #endif // __LP64__ |