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_cbrt(double x
)
132 return x
< 0 ? -pow(-x
, 1.0 / 3.0) : pow(x
, 1.0 / 3.0);
136 /*********************************************************************
139 static float CDECL
unix_cbrtf(float x
)
148 /*********************************************************************
151 static double CDECL
unix_ceil( double x
)
156 /*********************************************************************
159 static float CDECL
unix_ceilf( float x
)
164 /*********************************************************************
167 static double CDECL
unix_cos( double x
)
172 /*********************************************************************
175 static float CDECL
unix_cosf( float x
)
180 /*********************************************************************
183 static double CDECL
unix_cosh( double x
)
188 /*********************************************************************
191 static float CDECL
unix_coshf( float x
)
196 /*********************************************************************
199 static double CDECL
unix_erf(double x
)
204 /* Abramowitz and Stegun approximation, maximum error: 1.5*10^-7 */
206 int sign
= signbit(x
);
209 t
= 1 / (1 + 0.3275911 * x
);
210 y
= ((((1.061405429*t
- 1.453152027)*t
+ 1.421413741)*t
- 0.284496736)*t
+ 0.254829592)*t
;
211 y
= 1.0 - y
*exp(-x
*x
);
212 return sign
? -y
: y
;
216 /*********************************************************************
219 static float CDECL
unix_erff(float x
)
228 /*********************************************************************
231 static double CDECL
unix_erfc(double x
)
236 return 1 - unix_erf(x
);
240 /*********************************************************************
243 static float CDECL
unix_erfcf(float x
)
252 /*********************************************************************
255 static double CDECL
unix_exp( double x
)
260 /*********************************************************************
263 static float CDECL
unix_expf( float x
)
268 /*********************************************************************
271 static double CDECL
unix_exp2( double x
)
280 /*********************************************************************
283 static float CDECL
unix_exp2f( float x
)
292 /*********************************************************************
295 static double CDECL
unix_expm1(double x
)
304 /*********************************************************************
307 static float CDECL
unix_expm1f(float x
)
316 /*********************************************************************
319 static double CDECL
unix_floor( double x
)
324 /*********************************************************************
327 static float CDECL
unix_floorf( float x
)
332 /*********************************************************************
335 static double CDECL
unix_fma( double x
, double y
, double z
)
344 /*********************************************************************
347 static float CDECL
unix_fmaf( float x
, float y
, float z
)
350 return fmaf(x
, y
, z
);
356 /*********************************************************************
359 static double CDECL
unix_fmod( double x
, double y
)
364 /*********************************************************************
367 static float CDECL
unix_fmodf( float x
, float y
)
369 return fmodf( x
, y
);
372 /*********************************************************************
375 static double CDECL
unix_frexp( double x
, int *exp
)
377 return frexp( x
, exp
);
380 /*********************************************************************
383 static float CDECL
unix_frexpf( float x
, int *exp
)
385 return frexpf( x
, exp
);
388 /*********************************************************************
391 static double CDECL
unix_hypot(double x
, double y
)
393 return hypot( x
, y
);
396 /*********************************************************************
399 static float CDECL
unix_hypotf(float x
, float y
)
401 return hypotf( x
, y
);
404 /*********************************************************************
407 static double CDECL
unix_j0(double num
)
412 FIXME("not implemented\n");
417 /*********************************************************************
420 static double CDECL
unix_j1(double num
)
425 FIXME("not implemented\n");
430 /*********************************************************************
433 static double CDECL
unix_jn(int n
, double num
)
438 FIXME("not implemented\n");
443 /*********************************************************************
446 static double CDECL
unix_ldexp(double num
, int exp
)
448 return ldexp( num
, exp
);
451 /*********************************************************************
454 static double CDECL
unix_lgamma(double x
)
459 FIXME( "not implemented\n" );
464 /*********************************************************************
467 static float CDECL
unix_lgammaf(float x
)
472 FIXME( "not implemented\n" );
477 /*********************************************************************
480 static __int64 CDECL
unix_llrint(double x
)
485 return x
>= 0 ? floor(x
+ 0.5) : ceil(x
- 0.5);
489 /*********************************************************************
492 static __int64 CDECL
unix_llrintf(float x
)
497 return x
>= 0 ? floorf(x
+ 0.5) : ceilf(x
- 0.5);
501 /*********************************************************************
504 static double CDECL
unix_log( double x
)
509 /*********************************************************************
512 static float CDECL
unix_logf( float x
)
517 /*********************************************************************
520 static double CDECL
unix_log10( double x
)
525 /*********************************************************************
528 static float CDECL
unix_log10f( float x
)
533 /*********************************************************************
536 static double CDECL
unix_log1p(double x
)
545 /*********************************************************************
548 static float CDECL
unix_log1pf(float x
)
557 /*********************************************************************
560 static double CDECL
unix_log2(double x
)
565 return log(x
) / log(2);
569 /*********************************************************************
572 static float CDECL
unix_log2f(float x
)
581 /*********************************************************************
584 static double CDECL
unix_logb( double x
)
589 /*********************************************************************
592 static float CDECL
unix_logbf( float x
)
597 /*********************************************************************
600 static int CDECL
unix_lrint(double x
)
605 return x
>= 0 ? floor(x
+ 0.5) : ceil(x
- 0.5);
609 /*********************************************************************
612 static int CDECL
unix_lrintf(float x
)
617 return x
>= 0 ? floorf(x
+ 0.5) : ceilf(x
- 0.5);
621 /*********************************************************************
624 static double CDECL
unix_modf( double x
, double *iptr
)
626 return modf( x
, iptr
);
629 /*********************************************************************
632 static float CDECL
unix_modff( float x
, float *iptr
)
634 return modff( x
, iptr
);
637 /*********************************************************************
640 static double CDECL
unix_nearbyint(double num
)
642 #ifdef HAVE_NEARBYINT
643 return nearbyint(num
);
645 return num
>= 0 ? floor(num
+ 0.5) : ceil(num
- 0.5);
649 /*********************************************************************
652 static float CDECL
unix_nearbyintf(float num
)
654 #ifdef HAVE_NEARBYINTF
655 return nearbyintf(num
);
657 return unix_nearbyint(num
);
661 /*********************************************************************
664 static double CDECL
unix_nextafter(double num
, double next
)
666 return nextafter(num
,next
);
669 /*********************************************************************
672 static float CDECL
unix_nextafterf(float num
, float next
)
674 return nextafterf(num
,next
);
677 /*********************************************************************
680 static double CDECL
unix_nexttoward(double num
, double next
)
682 #ifdef HAVE_NEXTTOWARD
683 return nexttoward(num
, next
);
685 FIXME("not implemented\n");
690 /*********************************************************************
693 static float CDECL
unix_nexttowardf(float num
, double next
)
695 #ifdef HAVE_NEXTTOWARDF
696 return nexttowardf(num
, next
);
698 FIXME("not implemented\n");
703 /*********************************************************************
706 static double CDECL
unix_pow( double x
, double y
)
711 /*********************************************************************
714 static float CDECL
unix_powf( float x
, float y
)
719 /*********************************************************************
722 static double CDECL
unix_remainder(double x
, double y
)
724 #ifdef HAVE_REMAINDER
725 return remainder(x
, y
);
727 FIXME( "not implemented\n" );
732 /*********************************************************************
735 static float CDECL
unix_remainderf(float x
, float y
)
737 #ifdef HAVE_REMAINDERF
738 return remainderf(x
, y
);
740 FIXME( "not implemented\n" );
745 /*********************************************************************
748 static double CDECL
unix_remquo(double x
, double y
, int *quo
)
751 return remquo(x
, y
, quo
);
753 FIXME( "not implemented\n" );
758 /*********************************************************************
761 static float CDECL
unix_remquof(float x
, float y
, int *quo
)
764 return remquof(x
, y
, quo
);
766 FIXME( "not implemented\n" );
771 /*********************************************************************
774 static double CDECL
unix_rint(double x
)
779 return x
>= 0 ? floor(x
+ 0.5) : ceil(x
- 0.5);
783 /*********************************************************************
786 static float CDECL
unix_rintf(float x
)
791 return x
>= 0 ? floorf(x
+ 0.5) : ceilf(x
- 0.5);
795 /*********************************************************************
798 static double CDECL
unix_round(double x
)
807 /*********************************************************************
810 static float CDECL
unix_roundf(float x
)
815 return unix_round(x
);
819 /*********************************************************************
822 static int CDECL
unix_lround(double x
)
827 return unix_round(x
);
831 /*********************************************************************
834 static int CDECL
unix_lroundf(float x
)
839 return unix_lround(x
);
843 /*********************************************************************
846 static __int64 CDECL
unix_llround(double x
)
851 return unix_round(x
);
855 /*********************************************************************
858 static __int64 CDECL
unix_llroundf(float x
)
863 return unix_llround(x
);
867 /*********************************************************************
870 static double CDECL
unix_sin( double x
)
875 /*********************************************************************
878 static float CDECL
unix_sinf( float x
)
883 /*********************************************************************
886 static double CDECL
unix_sinh( double x
)
891 /*********************************************************************
894 static float CDECL
unix_sinhf( float x
)
899 /*********************************************************************
902 static double CDECL
unix_tan( double x
)
907 /*********************************************************************
910 static float CDECL
unix_tanf( float x
)
915 /*********************************************************************
918 static double CDECL
unix_tanh( double x
)
923 /*********************************************************************
926 static float CDECL
unix_tanhf( float x
)
931 /*********************************************************************
934 static double CDECL
unix_tgamma(double x
)
939 FIXME( "not implemented\n" );
944 /*********************************************************************
947 static double CDECL
unix_trunc(double x
)
952 return (x
> 0) ? floor(x
) : ceil(x
);
956 /*********************************************************************
959 static float CDECL
unix_truncf(float x
)
964 return unix_trunc(x
);
968 /*********************************************************************
971 static float CDECL
unix_tgammaf(float x
)
976 FIXME( "not implemented\n" );
981 /*********************************************************************
984 static double CDECL
unix_y0(double num
)
989 FIXME("not implemented\n");
994 /*********************************************************************
997 static double CDECL
unix_y1(double num
)
1002 FIXME("not implemented\n");
1007 /*********************************************************************
1010 static double CDECL
unix_yn(int order
, double num
)
1013 return yn(order
,num
);
1015 FIXME("not implemented\n");
1020 static const struct unix_funcs funcs
=
1115 NTSTATUS CDECL
__wine_init_unix_lib( HMODULE module
, DWORD reason
, const void *ptr_in
, void *ptr_out
)
1117 if (reason
!= DLL_PROCESS_ATTACH
) return STATUS_SUCCESS
;
1119 *(const struct unix_funcs
**)ptr_out
= &funcs
;
1120 return STATUS_SUCCESS
;