msvcrt: Import cosf implementation from musl.
[wine.git] / dlls / msvcrt / unixlib.c
blob1cec98ae3d40004becd92d926b31a14443330ed4
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 * acosh
48 static double CDECL unix_acosh(double x)
50 #ifdef HAVE_ACOSH
51 return acosh(x);
52 #else
53 if (!isfinite(x*x)) return log(2) + log(x);
54 return log(x + sqrt(x*x-1));
55 #endif
58 /*********************************************************************
59 * acoshf
61 static float CDECL unix_acoshf(float x)
63 #ifdef HAVE_ACOSHF
64 return acoshf(x);
65 #else
66 return unix_acosh(x);
67 #endif
70 /*********************************************************************
71 * asinh
73 static double CDECL unix_asinh(double x)
75 #ifdef HAVE_ASINH
76 return asinh(x);
77 #else
78 if (!isfinite(x*x+1))
80 if (x > 0) return log(2) + log(x);
81 else return -log(2) - log(-x);
83 return log(x + sqrt(x*x+1));
84 #endif
87 /*********************************************************************
88 * asinhf
90 static float CDECL unix_asinhf(float x)
92 #ifdef HAVE_ASINHF
93 return asinhf(x);
94 #else
95 return unix_asinh(x);
96 #endif
99 /*********************************************************************
100 * atanh
102 static double CDECL unix_atanh(double x)
104 #ifdef HAVE_ATANH
105 return atanh(x);
106 #else
107 if (-1e-6 < x && x < 1e-6) return x + x*x*x/3;
108 else return (log(1+x) - log(1-x)) / 2;
109 #endif
112 /*********************************************************************
113 * atanhf
115 static float CDECL unix_atanhf(float x)
117 #ifdef HAVE_ATANHF
118 return atanhf(x);
119 #else
120 return unix_atanh(x);
121 #endif
124 /*********************************************************************
125 * cosh
127 static double CDECL unix_cosh( double x )
129 return cosh( x );
132 /*********************************************************************
133 * coshf
135 static float CDECL unix_coshf( float x )
137 return coshf( x );
140 /*********************************************************************
141 * exp
143 static double CDECL unix_exp( double x )
145 return exp( x );
148 /*********************************************************************
149 * expf
151 static float CDECL unix_expf( float x )
153 return expf( x );
156 /*********************************************************************
157 * exp2
159 static double CDECL unix_exp2( double x )
161 #ifdef HAVE_EXP2
162 return exp2(x);
163 #else
164 return pow(2, x);
165 #endif
168 /*********************************************************************
169 * exp2f
171 static float CDECL unix_exp2f( float x )
173 #ifdef HAVE_EXP2F
174 return exp2f(x);
175 #else
176 return unix_exp2(x);
177 #endif
180 /*********************************************************************
181 * expm1
183 static double CDECL unix_expm1(double x)
185 #ifdef HAVE_EXPM1
186 return expm1(x);
187 #else
188 return exp(x) - 1;
189 #endif
192 /*********************************************************************
193 * expm1f
195 static float CDECL unix_expm1f(float x)
197 #ifdef HAVE_EXPM1F
198 return expm1f(x);
199 #else
200 return exp(x) - 1;
201 #endif
204 /*********************************************************************
205 * fma
207 static double CDECL unix_fma( double x, double y, double z )
209 #ifdef HAVE_FMA
210 return fma(x, y, z);
211 #else
212 return x * y + z;
213 #endif
216 /*********************************************************************
217 * fmaf
219 static float CDECL unix_fmaf( float x, float y, float z )
221 #ifdef HAVE_FMAF
222 return fmaf(x, y, z);
223 #else
224 return x * y + z;
225 #endif
228 /*********************************************************************
229 * frexp
231 static double CDECL unix_frexp( double x, int *exp )
233 return frexp( x, exp );
236 /*********************************************************************
237 * frexpf
239 static float CDECL unix_frexpf( float x, int *exp )
241 return frexpf( x, exp );
244 /*********************************************************************
245 * hypot
247 static double CDECL unix_hypot(double x, double y)
249 return hypot( x, y );
252 /*********************************************************************
253 * hypotf
255 static float CDECL unix_hypotf(float x, float y)
257 return hypotf( x, y );
260 /*********************************************************************
261 * ldexp
263 static double CDECL unix_ldexp(double num, int exp)
265 return ldexp( num, exp );
268 /*********************************************************************
269 * lgamma
271 static double CDECL unix_lgamma(double x)
273 #ifdef HAVE_LGAMMA
274 return lgamma(x);
275 #else
276 FIXME( "not implemented\n" );
277 return 0;
278 #endif
281 /*********************************************************************
282 * lgammaf
284 static float CDECL unix_lgammaf(float x)
286 #ifdef HAVE_LGAMMAF
287 return lgammaf(x);
288 #else
289 FIXME( "not implemented\n" );
290 return 0;
291 #endif
294 /*********************************************************************
295 * log
297 static double CDECL unix_log( double x )
299 return log( x );
302 /*********************************************************************
303 * logf
305 static float CDECL unix_logf( float x )
307 return logf( x );
310 /*********************************************************************
311 * log10
313 static double CDECL unix_log10( double x )
315 return log10( x );
318 /*********************************************************************
319 * log10f
321 static float CDECL unix_log10f( float x )
323 return log10f( x );
326 /*********************************************************************
327 * log1p
329 static double CDECL unix_log1p(double x)
331 #ifdef HAVE_LOG1P
332 return log1p(x);
333 #else
334 return log(1 + x);
335 #endif
338 /*********************************************************************
339 * log1pf
341 static float CDECL unix_log1pf(float x)
343 #ifdef HAVE_LOG1PF
344 return log1pf(x);
345 #else
346 return log(1 + x);
347 #endif
350 /*********************************************************************
351 * log2
353 static double CDECL unix_log2(double x)
355 #ifdef HAVE_LOG2
356 return log2(x);
357 #else
358 return log(x) / log(2);
359 #endif
362 /*********************************************************************
363 * log2f
365 static float CDECL unix_log2f(float x)
367 #ifdef HAVE_LOG2F
368 return log2f(x);
369 #else
370 return unix_log2(x);
371 #endif
374 /*********************************************************************
375 * pow
377 static double CDECL unix_pow( double x, double y )
379 return pow( x, y );
382 /*********************************************************************
383 * powf
385 static float CDECL unix_powf( float x, float y )
387 return powf( x, y );
390 /*********************************************************************
391 * sinf
393 static float CDECL unix_sinf( float x )
395 return sinf( x );
398 /*********************************************************************
399 * sinh
401 static double CDECL unix_sinh( double x )
403 return sinh( x );
406 /*********************************************************************
407 * sinhf
409 static float CDECL unix_sinhf( float x )
411 return sinhf( x );
414 /*********************************************************************
415 * tanf
417 static float CDECL unix_tanf( float x )
419 return tanf( x );
422 /*********************************************************************
423 * tanh
425 static double CDECL unix_tanh( double x )
427 return tanh( x );
430 /*********************************************************************
431 * tanhf
433 static float CDECL unix_tanhf( float x )
435 return tanhf( x );
438 /*********************************************************************
439 * tgamma
441 static double CDECL unix_tgamma(double x)
443 #ifdef HAVE_TGAMMA
444 return tgamma(x);
445 #else
446 FIXME( "not implemented\n" );
447 return 0;
448 #endif
451 /*********************************************************************
452 * tgammaf
454 static float CDECL unix_tgammaf(float x)
456 #ifdef HAVE_TGAMMAF
457 return tgammaf(x);
458 #else
459 FIXME( "not implemented\n" );
460 return 0;
461 #endif
464 static const struct unix_funcs funcs =
466 unix_acosh,
467 unix_acoshf,
468 unix_asinh,
469 unix_asinhf,
470 unix_atanh,
471 unix_atanhf,
472 unix_cosh,
473 unix_coshf,
474 unix_exp,
475 unix_expf,
476 unix_exp2,
477 unix_exp2f,
478 unix_expm1,
479 unix_expm1f,
480 unix_fma,
481 unix_fmaf,
482 unix_frexp,
483 unix_frexpf,
484 unix_hypot,
485 unix_hypotf,
486 unix_ldexp,
487 unix_lgamma,
488 unix_lgammaf,
489 unix_log,
490 unix_logf,
491 unix_log10,
492 unix_log10f,
493 unix_log1p,
494 unix_log1pf,
495 unix_log2,
496 unix_log2f,
497 unix_pow,
498 unix_powf,
499 unix_sinf,
500 unix_sinh,
501 unix_sinhf,
502 unix_tanf,
503 unix_tanh,
504 unix_tanhf,
505 unix_tgamma,
506 unix_tgammaf,
509 NTSTATUS CDECL __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out )
511 if (reason != DLL_PROCESS_ATTACH) return STATUS_SUCCESS;
512 TRACE( "\n" );
513 *(const struct unix_funcs **)ptr_out = &funcs;
514 return STATUS_SUCCESS;