msvcrt: Import atanh implementation from musl.
[wine.git] / dlls / msvcrt / unixlib.c
blob6d3a3bd5a792bee43fb88e7f98e397270b7888cd
1 /*
2 * MSVCRT Unix interface
4 * Copyright 2020 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #if 0
22 #pragma makedep unix
23 #endif
25 #include "config.h"
26 #include "wine/port.h"
28 #include <stdio.h>
29 #include <stdarg.h>
30 #define __USE_ISOC9X 1
31 #define __USE_ISOC99 1
32 #include <math.h>
33 #ifdef HAVE_IEEEFP_H
34 #include <ieeefp.h>
35 #endif
37 #include "ntstatus.h"
38 #define WIN32_NO_STATUS
39 #include "winternl.h"
40 #include "unixlib.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
45 /*********************************************************************
46 * cosh
48 static double CDECL unix_cosh( double x )
50 return cosh( x );
53 /*********************************************************************
54 * coshf
56 static float CDECL unix_coshf( float x )
58 return coshf( x );
61 /*********************************************************************
62 * exp
64 static double CDECL unix_exp( double x )
66 return exp( x );
69 /*********************************************************************
70 * expf
72 static float CDECL unix_expf( float x )
74 return expf( x );
77 /*********************************************************************
78 * exp2
80 static double CDECL unix_exp2( double x )
82 #ifdef HAVE_EXP2
83 return exp2(x);
84 #else
85 return pow(2, x);
86 #endif
89 /*********************************************************************
90 * exp2f
92 static float CDECL unix_exp2f( float x )
94 #ifdef HAVE_EXP2F
95 return exp2f(x);
96 #else
97 return unix_exp2(x);
98 #endif
101 /*********************************************************************
102 * expm1
104 static double CDECL unix_expm1(double x)
106 #ifdef HAVE_EXPM1
107 return expm1(x);
108 #else
109 return exp(x) - 1;
110 #endif
113 /*********************************************************************
114 * expm1f
116 static float CDECL unix_expm1f(float x)
118 #ifdef HAVE_EXPM1F
119 return expm1f(x);
120 #else
121 return exp(x) - 1;
122 #endif
125 /*********************************************************************
126 * fma
128 static double CDECL unix_fma( double x, double y, double z )
130 #ifdef HAVE_FMA
131 return fma(x, y, z);
132 #else
133 return x * y + z;
134 #endif
137 /*********************************************************************
138 * fmaf
140 static float CDECL unix_fmaf( float x, float y, float z )
142 #ifdef HAVE_FMAF
143 return fmaf(x, y, z);
144 #else
145 return x * y + z;
146 #endif
149 /*********************************************************************
150 * frexp
152 static double CDECL unix_frexp( double x, int *exp )
154 return frexp( x, exp );
157 /*********************************************************************
158 * frexpf
160 static float CDECL unix_frexpf( float x, int *exp )
162 return frexpf( x, exp );
165 /*********************************************************************
166 * hypot
168 static double CDECL unix_hypot(double x, double y)
170 return hypot( x, y );
173 /*********************************************************************
174 * hypotf
176 static float CDECL unix_hypotf(float x, float y)
178 return hypotf( x, y );
181 /*********************************************************************
182 * ldexp
184 static double CDECL unix_ldexp(double num, int exp)
186 return ldexp( num, exp );
189 /*********************************************************************
190 * lgamma
192 static double CDECL unix_lgamma(double x)
194 #ifdef HAVE_LGAMMA
195 return lgamma(x);
196 #else
197 FIXME( "not implemented\n" );
198 return 0;
199 #endif
202 /*********************************************************************
203 * lgammaf
205 static float CDECL unix_lgammaf(float x)
207 #ifdef HAVE_LGAMMAF
208 return lgammaf(x);
209 #else
210 FIXME( "not implemented\n" );
211 return 0;
212 #endif
215 /*********************************************************************
216 * log
218 static double CDECL unix_log( double x )
220 return log( x );
223 /*********************************************************************
224 * logf
226 static float CDECL unix_logf( float x )
228 return logf( x );
231 /*********************************************************************
232 * log10
234 static double CDECL unix_log10( double x )
236 return log10( x );
239 /*********************************************************************
240 * log10f
242 static float CDECL unix_log10f( float x )
244 return log10f( x );
247 /*********************************************************************
248 * log1p
250 static double CDECL unix_log1p(double x)
252 #ifdef HAVE_LOG1P
253 return log1p(x);
254 #else
255 return log(1 + x);
256 #endif
259 /*********************************************************************
260 * log1pf
262 static float CDECL unix_log1pf(float x)
264 #ifdef HAVE_LOG1PF
265 return log1pf(x);
266 #else
267 return log(1 + x);
268 #endif
271 /*********************************************************************
272 * log2
274 static double CDECL unix_log2(double x)
276 #ifdef HAVE_LOG2
277 return log2(x);
278 #else
279 return log(x) / log(2);
280 #endif
283 /*********************************************************************
284 * log2f
286 static float CDECL unix_log2f(float x)
288 #ifdef HAVE_LOG2F
289 return log2f(x);
290 #else
291 return unix_log2(x);
292 #endif
295 /*********************************************************************
296 * pow
298 static double CDECL unix_pow( double x, double y )
300 return pow( x, y );
303 /*********************************************************************
304 * powf
306 static float CDECL unix_powf( float x, float y )
308 return powf( x, y );
311 /*********************************************************************
312 * sinh
314 static double CDECL unix_sinh( double x )
316 return sinh( x );
319 /*********************************************************************
320 * sinhf
322 static float CDECL unix_sinhf( float x )
324 return sinhf( x );
327 /*********************************************************************
328 * tanh
330 static double CDECL unix_tanh( double x )
332 return tanh( x );
335 /*********************************************************************
336 * tanhf
338 static float CDECL unix_tanhf( float x )
340 return tanhf( x );
343 /*********************************************************************
344 * tgamma
346 static double CDECL unix_tgamma(double x)
348 #ifdef HAVE_TGAMMA
349 return tgamma(x);
350 #else
351 FIXME( "not implemented\n" );
352 return 0;
353 #endif
356 /*********************************************************************
357 * tgammaf
359 static float CDECL unix_tgammaf(float x)
361 #ifdef HAVE_TGAMMAF
362 return tgammaf(x);
363 #else
364 FIXME( "not implemented\n" );
365 return 0;
366 #endif
369 static const struct unix_funcs funcs =
371 unix_cosh,
372 unix_coshf,
373 unix_exp,
374 unix_expf,
375 unix_exp2,
376 unix_exp2f,
377 unix_expm1,
378 unix_expm1f,
379 unix_fma,
380 unix_fmaf,
381 unix_frexp,
382 unix_frexpf,
383 unix_hypot,
384 unix_hypotf,
385 unix_ldexp,
386 unix_lgamma,
387 unix_lgammaf,
388 unix_log,
389 unix_logf,
390 unix_log10,
391 unix_log10f,
392 unix_log1p,
393 unix_log1pf,
394 unix_log2,
395 unix_log2f,
396 unix_pow,
397 unix_powf,
398 unix_sinh,
399 unix_sinhf,
400 unix_tanh,
401 unix_tanhf,
402 unix_tgamma,
403 unix_tgammaf,
406 NTSTATUS CDECL __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out )
408 if (reason != DLL_PROCESS_ATTACH) return STATUS_SUCCESS;
409 TRACE( "\n" );
410 *(const struct unix_funcs **)ptr_out = &funcs;
411 return STATUS_SUCCESS;