blob: 360ee2bd9d374b194aba6a02d179ce0505001052 [file] [log] [blame]
Elliott Hughesa0ee0782013-01-30 19:06:37 -08001/*
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
Elliott Hughes5ea0b062017-07-13 17:30:06 -070020#if !defined(__LP64__)
21
22// The BSD "long double" functions are broken when sizeof(long double) == sizeof(double).
23// Android works around those cases by replacing the broken functions with our own trivial stubs
24// that call the regular "double" function.
Elliott Hughesa0ee0782013-01-30 19:06:37 -080025
Elliott Hughesa0ee0782013-01-30 19:06:37 -080026long double copysignl(long double a1, long double a2) { return copysign(a1, a2); }
Elliott Hughese57d7722017-11-08 10:04:32 -080027#if defined(__arm__) // See builtins.cpp.
28long double fmal(long double a1, long double a2, long double a3) { return fma(a1, a2, a3); }
29#endif
Elliott Hughesa0ee0782013-01-30 19:06:37 -080030long double fmaxl(long double a1, long double a2) { return fmax(a1, a2); }
31long double fmodl(long double a1, long double a2) { return fmod(a1, a2); }
32long double fminl(long double a1, long double a2) { return fmin(a1, a2); }
33int ilogbl(long double a1) { return ilogb(a1); }
Elliott Hughesa0ee0782013-01-30 19:06:37 -080034long long llrintl(long double a1) { return llrint(a1); }
jzha136f3ea0932015-06-12 09:15:02 -070035#if !defined(__i386__) // x86 has an assembler lrint/lrintl.
Elliott Hughesa0ee0782013-01-30 19:06:37 -080036long lrintl(long double a1) { return lrint(a1); }
jzha136f3ea0932015-06-12 09:15:02 -070037#endif
Elliott Hughesa0ee0782013-01-30 19:06:37 -080038long long llroundl(long double a1) { return llround(a1); }
39long lroundl(long double a1) { return lround(a1); }
Calin Juravle4d77c112014-03-14 17:56:46 +000040long double modfl(long double a1, long double* a2) { double i; double f = modf(a1, &i); *a2 = i; return f; }
Calin Juravle1abc9ff2014-04-17 18:17:32 +010041float nexttowardf(float a1, long double a2) { return nextafterf(a1, (float) a2); }
Elliott Hughesa0ee0782013-01-30 19:06:37 -080042long double roundl(long double a1) { return round(a1); }
Calin Juravle4d77c112014-03-14 17:56:46 +000043
44#endif // __LP64__
Elliott Hughes5ea0b062017-07-13 17:30:06 -070045
46// FreeBSD doesn't have ld128 implementations of powl or tgammal, so both LP32 and LP64 need these.
47long double powl(long double x, long double y) { return pow(x, y); }
48long double tgammal(long double x) { return tgamma(x); }