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
26 #include "wine/port.h"
30 #define __USE_ISOC9X 1
31 #define __USE_ISOC99 1
38 #define WIN32_NO_STATUS
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
45 /*********************************************************************
48 static double CDECL
unix_acosh(double x
)
53 if (!isfinite(x
*x
)) return log(2) + log(x
);
54 return log(x
+ sqrt(x
*x
-1));
58 /*********************************************************************
61 static float CDECL
unix_acoshf(float x
)
70 /*********************************************************************
73 static double CDECL
unix_asinh(double x
)
80 if (x
> 0) return log(2) + log(x
);
81 else return -log(2) - log(-x
);
83 return log(x
+ sqrt(x
*x
+1));
87 /*********************************************************************
90 static float CDECL
unix_asinhf(float x
)
99 /*********************************************************************
102 static double CDECL
unix_atanh(double x
)
107 if (-1e-6 < x
&& x
< 1e-6) return x
+ x
*x
*x
/3;
108 else return (log(1+x
) - log(1-x
)) / 2;
112 /*********************************************************************
115 static float CDECL
unix_atanhf(float x
)
120 return unix_atanh(x
);
124 /*********************************************************************
127 static double CDECL
unix_ceil( double x
)
132 /*********************************************************************
135 static float CDECL
unix_ceilf( float x
)
140 /*********************************************************************
143 static double CDECL
unix_cos( double x
)
148 /*********************************************************************
151 static float CDECL
unix_cosf( float x
)
156 /*********************************************************************
159 static double CDECL
unix_cosh( double x
)
164 /*********************************************************************
167 static float CDECL
unix_coshf( float x
)
172 /*********************************************************************
175 static double CDECL
unix_erf(double x
)
180 /* Abramowitz and Stegun approximation, maximum error: 1.5*10^-7 */
182 int sign
= signbit(x
);
185 t
= 1 / (1 + 0.3275911 * x
);
186 y
= ((((1.061405429*t
- 1.453152027)*t
+ 1.421413741)*t
- 0.284496736)*t
+ 0.254829592)*t
;
187 y
= 1.0 - y
*exp(-x
*x
);
188 return sign
? -y
: y
;
192 /*********************************************************************
195 static float CDECL
unix_erff(float x
)
204 /*********************************************************************
207 static double CDECL
unix_erfc(double x
)
212 return 1 - unix_erf(x
);
216 /*********************************************************************
219 static float CDECL
unix_erfcf(float x
)
228 /*********************************************************************
231 static double CDECL
unix_exp( double x
)
236 /*********************************************************************
239 static float CDECL
unix_expf( float x
)
244 /*********************************************************************
247 static double CDECL
unix_exp2( double x
)
256 /*********************************************************************
259 static float CDECL
unix_exp2f( float x
)
268 /*********************************************************************
271 static double CDECL
unix_expm1(double x
)
280 /*********************************************************************
283 static float CDECL
unix_expm1f(float x
)
292 /*********************************************************************
295 static double CDECL
unix_floor( double x
)
300 /*********************************************************************
303 static float CDECL
unix_floorf( float x
)
308 /*********************************************************************
311 static double CDECL
unix_fma( double x
, double y
, double z
)
320 /*********************************************************************
323 static float CDECL
unix_fmaf( float x
, float y
, float z
)
326 return fmaf(x
, y
, z
);
332 /*********************************************************************
335 static double CDECL
unix_fmod( double x
, double y
)
340 /*********************************************************************
343 static float CDECL
unix_fmodf( float x
, float y
)
345 return fmodf( x
, y
);
348 /*********************************************************************
351 static double CDECL
unix_frexp( double x
, int *exp
)
353 return frexp( x
, exp
);
356 /*********************************************************************
359 static float CDECL
unix_frexpf( float x
, int *exp
)
361 return frexpf( x
, exp
);
364 /*********************************************************************
367 static double CDECL
unix_hypot(double x
, double y
)
369 return hypot( x
, y
);
372 /*********************************************************************
375 static float CDECL
unix_hypotf(float x
, float y
)
377 return hypotf( x
, y
);
380 /*********************************************************************
383 static double CDECL
unix_ldexp(double num
, int exp
)
385 return ldexp( num
, exp
);
388 /*********************************************************************
391 static double CDECL
unix_lgamma(double x
)
396 FIXME( "not implemented\n" );
401 /*********************************************************************
404 static float CDECL
unix_lgammaf(float x
)
409 FIXME( "not implemented\n" );
414 /*********************************************************************
417 static double CDECL
unix_log( double x
)
422 /*********************************************************************
425 static float CDECL
unix_logf( float x
)
430 /*********************************************************************
433 static double CDECL
unix_log10( double x
)
438 /*********************************************************************
441 static float CDECL
unix_log10f( float x
)
446 /*********************************************************************
449 static double CDECL
unix_log1p(double x
)
458 /*********************************************************************
461 static float CDECL
unix_log1pf(float x
)
470 /*********************************************************************
473 static double CDECL
unix_log2(double x
)
478 return log(x
) / log(2);
482 /*********************************************************************
485 static float CDECL
unix_log2f(float x
)
494 /*********************************************************************
497 static double CDECL
unix_logb( double x
)
502 /*********************************************************************
505 static float CDECL
unix_logbf( float x
)
510 /*********************************************************************
513 static double CDECL
unix_modf( double x
, double *iptr
)
515 return modf( x
, iptr
);
518 /*********************************************************************
521 static float CDECL
unix_modff( float x
, float *iptr
)
523 return modff( x
, iptr
);
526 /*********************************************************************
529 static double CDECL
unix_pow( double x
, double y
)
534 /*********************************************************************
537 static float CDECL
unix_powf( float x
, float y
)
542 /*********************************************************************
545 static double CDECL
unix_remainder(double x
, double y
)
547 #ifdef HAVE_REMAINDER
548 return remainder(x
, y
);
550 FIXME( "not implemented\n" );
555 /*********************************************************************
558 static float CDECL
unix_remainderf(float x
, float y
)
560 #ifdef HAVE_REMAINDERF
561 return remainderf(x
, y
);
563 FIXME( "not implemented\n" );
568 /*********************************************************************
571 static double CDECL
unix_remquo(double x
, double y
, int *quo
)
574 return remquo(x
, y
, quo
);
576 FIXME( "not implemented\n" );
581 /*********************************************************************
584 static float CDECL
unix_remquof(float x
, float y
, int *quo
)
587 return remquof(x
, y
, quo
);
589 FIXME( "not implemented\n" );
594 /*********************************************************************
597 static double CDECL
unix_sin( double x
)
602 /*********************************************************************
605 static float CDECL
unix_sinf( float x
)
610 /*********************************************************************
613 static double CDECL
unix_sinh( double x
)
618 /*********************************************************************
621 static float CDECL
unix_sinhf( float x
)
626 /*********************************************************************
629 static double CDECL
unix_tan( double x
)
634 /*********************************************************************
637 static float CDECL
unix_tanf( float x
)
642 /*********************************************************************
645 static double CDECL
unix_tanh( double x
)
650 /*********************************************************************
653 static float CDECL
unix_tanhf( float x
)
658 /*********************************************************************
661 static double CDECL
unix_tgamma(double x
)
666 FIXME( "not implemented\n" );
671 /*********************************************************************
674 static double CDECL
unix_trunc(double x
)
679 return (x
> 0) ? floor(x
) : ceil(x
);
683 /*********************************************************************
686 static float CDECL
unix_truncf(float x
)
691 return unix_trunc(x
);
695 /*********************************************************************
698 static float CDECL
unix_tgammaf(float x
)
703 FIXME( "not implemented\n" );
708 static const struct unix_funcs funcs
=
777 NTSTATUS CDECL
__wine_init_unix_lib( HMODULE module
, DWORD reason
, const void *ptr_in
, void *ptr_out
)
779 if (reason
!= DLL_PROCESS_ATTACH
) return STATUS_SUCCESS
;
781 *(const struct unix_funcs
**)ptr_out
= &funcs
;
782 return STATUS_SUCCESS
;