1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *  * Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *  * Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in
12  *    the documentation and/or other materials provided with the
13  *    distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #include <math.h>
30 #include <assert.h>
31 
32 /* Any 64-bit Android math library should provide these functions,
33  * so these wrappers are only needed for 32-bit systems.
34  */
35 #ifndef __LP64__
36 
37 /*
38  * On 32-bit Android, long double and double are identical, hence
39  * nexttoward is the same as nextafter.
40  */
41 
nexttoward(double d,long double td)42 __attribute__((weak)) double nexttoward(double d, long double td) {
43   return nextafter(d, (double)td);
44 }
45 
nexttowardf(float f,long double td)46 __attribute__((weak)) float nexttowardf(float f, long double td) {
47   return nextafterf(f, (float)td);
48 }
49 
nexttowardl(long double ld,long double td)50 __attribute__((weak)) long double nexttowardl(long double ld, long double td) {
51   return nextafter((double)ld, (double)td);
52 }
53 
acosl(long double x)54 __attribute__((weak)) long double acosl(long double x) { return acos((double)x); }
asinl(long double x)55 __attribute__((weak)) long double asinl(long double x) { return asin((double)x); }
atanl(long double x)56 __attribute__((weak)) long double atanl(long double x) { return atan((double)x); }
atan2l(long double x,long double y)57 __attribute__((weak)) long double atan2l(long double x, long double y) { return atan2((double)x, (double)y); }
cosl(long double x)58 __attribute__((weak)) long double cosl(long double x) { return cos((double)x); }
coshl(long double x)59 __attribute__((weak)) long double coshl(long double x) { return cosh((double)x); }
expl(long double x)60 __attribute__((weak)) long double expl(long double x) { return exp((double)x); }
fmodl(long double x,long double y)61 __attribute__((weak)) long double fmodl(long double x, long double y) { return fmod((double)x, (double)y); }
powl(long double x,long double y)62 __attribute__((weak)) long double powl(long double x, long double y) { return pow((double)x, (double)y); }
sinl(long double x)63 __attribute__((weak)) long double sinl(long double x) { return sin((double)x); }
sinhl(long double x)64 __attribute__((weak)) long double sinhl(long double x) { return sinh((double)x); }
sqrtl(long double x)65 __attribute__((weak)) long double sqrtl(long double x) { return sqrt((double)x); }
tanl(long double x)66 __attribute__((weak)) long double tanl(long double x) { return tan((double)x); }
tanhl(long double x)67 __attribute__((weak)) long double tanhl(long double x) { return tanh((double)x); }
acoshl(long double x)68 __attribute__((weak)) long double acoshl(long double x) { return acosh((double)x); }
asinhl(long double x)69 __attribute__((weak)) long double asinhl(long double x) { return asinh((double)x); }
atanhl(long double x)70 __attribute__((weak)) long double atanhl(long double x) { return atanh((double)x); }
cbrtl(long double x)71 __attribute__((weak)) long double cbrtl(long double x) { return cbrt((double)x); }
erfl(long double x)72 __attribute__((weak)) long double erfl(long double x) { return erf((double)x); }
erfcl(long double x)73 __attribute__((weak)) long double erfcl(long double x) { return erfc((double)x); }
expm1l(long double x)74 __attribute__((weak)) long double expm1l(long double x) { return expm1((double)x); }
hypotl(long double x,long double y)75 __attribute__((weak)) long double hypotl(long double x, long double y) { return hypot((double)x, (double)y); }
lgammal(long double x)76 __attribute__((weak)) long double lgammal(long double x) { return lgamma((double)x); }
llrintl(long double x)77 __attribute__((weak)) long long int llrintl(long double x) { return llrint((double)x); }
logl(long double x)78 __attribute__((weak)) long double logl(long double x) { return log((double)x); }
log1pl(long double x)79 __attribute__((weak)) long double log1pl(long double x) { return log1p((double)x); }
log2l(long double x)80 __attribute__((weak)) long double log2l(long double x) { return log2((double)x); }
logbl(long double x)81 __attribute__((weak)) long double logbl(long double x) { return logb((double)x); }
log10l(long double x)82 __attribute__((weak)) long double log10l(long double x) { return log10((double)x); }
nanl(const char * s)83 __attribute__((weak)) long double nanl(const char* s) { return nan(s); }
nearbyintl(long double x)84 __attribute__((weak)) long double nearbyintl(long double x) { return nearbyint((double)x); }
remainderl(long double x,long double y)85 __attribute__((weak)) long double remainderl(long double x, long double y) { return remainder((double)x, (double)y); }
remquol(long double x,long double y,int * i)86 __attribute__((weak)) long double remquol(long double x, long double y, int* i) { return remquo((double)x, (double)y, i); }
rintl(long double x)87 __attribute__((weak)) long double rintl(long double x) { return rint((double)x); }
lrintl(long double x)88 __attribute__((weak)) long int lrintl(long double x) { return lrint((double)x); }
tgammal(long double x)89 __attribute__((weak)) long double tgammal(long double x) { return tgamma((double)x); }
modfl(long double x,long double * y)90 __attribute__((weak)) long double modfl(long double x, long double* y) { return modf((double)x, (double *)y); }
exp2l(long double x)91 __attribute__((weak)) long double exp2l(long double x) { return exp2((double)x); }
92 
93 #endif  // !__LP64__
94