2 * Copyright (C) 2024 Mikulas Patocka
4 * This file is part of Ajla.
6 * Ajla is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation, either version 3 of the License, or (at your option) any later
11 * Ajla is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * Ajla. If not, see <https://www.gnu.org/licenses/>.
24 char *getenv(const char attr_unused
*name
)
31 void *mempcpy(void *dst
, const void *src
, size_t length
)
33 (void)memcpy(dst
, src
, length
);
34 return (char *)dst
+ length
;
39 char *strerror(int errnum
)
41 static char buffer
[6 + 1 + (sizeof(int) * 5 / 2 + 1) + 1] = "error ";
43 str_add_signed(&b
, NULL
, (intbig_t
)errnum
, 10);
49 size_t strnlen(const char *s
, size_t maxlen
)
52 for (l
= 0; l
< maxlen
; l
++)
59 #if !defined(HAVE_CBRT)
62 if (unlikely(x
<= 0)) {
66 return -pow(-x
, 1./3.);
72 #if !defined(HAVE_CBRTF)
75 if (unlikely(x
<= 0)) {
79 return -powf(-x
, 1./3.);
81 return powf(x
, 1./3.);
85 #if defined(HAVE_LONG_DOUBLE) && !defined(HAVE_CBRTL)
88 if (unlikely(x
<= 0)) {
92 return -powl(-x
, 1./3.);
94 return powl(x
, 1.L
/3.L
);
98 #if !defined(HAVE_ASINH)
99 double asinh(double x
)
101 return log(x
+ sqrt(x
* x
+ 1));
105 #if defined(HAVE_LONG_DOUBLE) && !defined(HAVE_ASINHL)
106 long double asinhl(long double x
)
108 return logl(x
+ sqrtl(x
* x
+ 1));
112 #if !defined(HAVE_ACOSH)
113 double acosh(double x
)
115 return log(x
+ sqrt(x
* x
- 1));
119 #if defined(HAVE_LONG_DOUBLE) && !defined(HAVE_ACOSHL)
120 long double acoshl(long double x
)
122 return logl(x
+ sqrtl(x
* x
- 1));
126 #if !defined(HAVE_ATANH)
127 double atanh(double x
)
129 return 0.5 * log((1 + x
) / (1 - x
));
133 #if defined(HAVE_LONG_DOUBLE) && !defined(HAVE_ATANHL)
134 long double atanhl(long double x
)
136 return 0.5 * logl((1 + x
) / (1 - x
));
140 #if !defined(HAVE_EXP2)
141 double exp2(double x
)
147 #if !defined(HAVE_EXP2F)
154 #if defined(HAVE_LONG_DOUBLE) && !defined(HAVE_EXP2L)
155 long double exp2l(long double x
)
161 #if defined(HAVE___FLOAT128) && defined(HAVE_LIBQUADMATH) && defined(HAVE_QUADMATH_H) && !defined(HAVE_EXP2Q)
162 __float128
exp2q(__float128 x
)
168 #if !defined(HAVE_EXP10)
169 double exp10(double x
)
175 #if !defined(HAVE_EXP10F)
176 float exp10f(float x
)
182 #if defined(HAVE_LONG_DOUBLE) && !defined(HAVE_EXP10L)
183 long double exp10l(long double x
)
189 #if defined(HAVE___FLOAT128) && defined(HAVE_LIBQUADMATH) && defined(HAVE_QUADMATH_H) && !defined(HAVE_EXP10Q)
190 __float128
exp10q(__float128 x
)
196 #if !defined(HAVE_LOG2)
197 double log2(double x
)
199 return log(x
) / log(2);
203 #if !defined(HAVE_LOG2F)
206 return logf(x
) / logf(2);
210 #if defined(HAVE_LONG_DOUBLE) && !defined(HAVE_LOG2L)
211 long double log2l(long double x
)
213 return logl(x
) / logl(2);
217 #if !defined(HAVE_TRUNC)
218 double trunc(double x
)
227 #if !defined(HAVE_TRUNCF)
228 float truncf(float x
)
237 #if defined(HAVE_LONG_DOUBLE) && !defined(HAVE_TRUNCL)
238 long double truncl(long double x
)
247 #if !defined(HAVE_RINT)
248 double rint(double x
)
251 return floor(x
+ 0.5);
253 return ceil(x
- 0.5);
257 #if !defined(HAVE_RINTF)
264 #if !defined(HAVE_MODFF)
265 float modff(float x
, float *iflt
)
268 double r
= modf(x
, &idbl
);