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 | |
Elliott Hughes | e332f65 | 2018-05-08 15:07:43 -0700 | [diff] [blame] | 17 | #define _GNU_SOURCE |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 18 | #include <float.h> |
| 19 | #include <math.h> |
| 20 | |
Elliott Hughes | 5ea0b06 | 2017-07-13 17:30:06 -0700 | [diff] [blame] | 21 | #if !defined(__LP64__) |
| 22 | |
| 23 | // The BSD "long double" functions are broken when sizeof(long double) == sizeof(double). |
| 24 | // Android works around those cases by replacing the broken functions with our own trivial stubs |
| 25 | // that call the regular "double" function. |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 26 | |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 27 | long double fmaxl(long double a1, long double a2) { return fmax(a1, a2); } |
| 28 | long double fmodl(long double a1, long double a2) { return fmod(a1, a2); } |
| 29 | long double fminl(long double a1, long double a2) { return fmin(a1, a2); } |
| 30 | int ilogbl(long double a1) { return ilogb(a1); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 31 | long long llrintl(long double a1) { return llrint(a1); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 32 | long lrintl(long double a1) { return lrint(a1); } |
| 33 | long long llroundl(long double a1) { return llround(a1); } |
| 34 | long lroundl(long double a1) { return lround(a1); } |
Calin Juravle | 4d77c11 | 2014-03-14 17:56:46 +0000 | [diff] [blame] | 35 | long double modfl(long double a1, long double* a2) { double i; double f = modf(a1, &i); *a2 = i; return f; } |
Calin Juravle | 1abc9ff | 2014-04-17 18:17:32 +0100 | [diff] [blame] | 36 | float nexttowardf(float a1, long double a2) { return nextafterf(a1, (float) a2); } |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 37 | long double roundl(long double a1) { return round(a1); } |
Elliott Hughes | ab52807 | 2018-07-24 00:01:52 +0000 | [diff] [blame] | 38 | void sincosl(long double x, long double* s, long double* c) { sincos(x, (double*) s, (double*) c); } |
Calin Juravle | 4d77c11 | 2014-03-14 17:56:46 +0000 | [diff] [blame] | 39 | |
| 40 | #endif // __LP64__ |
Elliott Hughes | 5ea0b06 | 2017-07-13 17:30:06 -0700 | [diff] [blame] | 41 | |
Elliott Hughes | 3984a99 | 2019-09-17 13:08:02 -0700 | [diff] [blame] | 42 | // FreeBSD doesn't have an ld128 implementation of tgammal, so both LP32 and LP64 need this. |
Elliott Hughes | 5ea0b06 | 2017-07-13 17:30:06 -0700 | [diff] [blame] | 43 | long double tgammal(long double x) { return tgamma(x); } |