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_ldexp(double num
, int exp
)
409 return ldexp( num
, exp
);
412 /*********************************************************************
415 static double CDECL
unix_lgamma(double x
)
420 FIXME( "not implemented\n" );
425 /*********************************************************************
428 static float CDECL
unix_lgammaf(float x
)
433 FIXME( "not implemented\n" );
438 /*********************************************************************
441 static __int64 CDECL
unix_llrint(double x
)
446 return x
>= 0 ? floor(x
+ 0.5) : ceil(x
- 0.5);
450 /*********************************************************************
453 static __int64 CDECL
unix_llrintf(float x
)
458 return x
>= 0 ? floorf(x
+ 0.5) : ceilf(x
- 0.5);
462 /*********************************************************************
465 static double CDECL
unix_log( double x
)
470 /*********************************************************************
473 static float CDECL
unix_logf( float x
)
478 /*********************************************************************
481 static double CDECL
unix_log10( double x
)
486 /*********************************************************************
489 static float CDECL
unix_log10f( float x
)
494 /*********************************************************************
497 static double CDECL
unix_log1p(double x
)
506 /*********************************************************************
509 static float CDECL
unix_log1pf(float x
)
518 /*********************************************************************
521 static double CDECL
unix_log2(double x
)
526 return log(x
) / log(2);
530 /*********************************************************************
533 static float CDECL
unix_log2f(float x
)
542 /*********************************************************************
545 static double CDECL
unix_logb( double x
)
550 /*********************************************************************
553 static float CDECL
unix_logbf( float x
)
558 /*********************************************************************
561 static int CDECL
unix_lrint(double x
)
566 return x
>= 0 ? floor(x
+ 0.5) : ceil(x
- 0.5);
570 /*********************************************************************
573 static int CDECL
unix_lrintf(float x
)
578 return x
>= 0 ? floorf(x
+ 0.5) : ceilf(x
- 0.5);
582 /*********************************************************************
585 static double CDECL
unix_modf( double x
, double *iptr
)
587 return modf( x
, iptr
);
590 /*********************************************************************
593 static float CDECL
unix_modff( float x
, float *iptr
)
595 return modff( x
, iptr
);
598 /*********************************************************************
601 static double CDECL
unix_nearbyint(double num
)
603 #ifdef HAVE_NEARBYINT
604 return nearbyint(num
);
606 return num
>= 0 ? floor(num
+ 0.5) : ceil(num
- 0.5);
610 /*********************************************************************
613 static float CDECL
unix_nearbyintf(float num
)
615 #ifdef HAVE_NEARBYINTF
616 return nearbyintf(num
);
618 return unix_nearbyint(num
);
622 /*********************************************************************
625 static double CDECL
unix_nextafter(double num
, double next
)
627 return nextafter(num
,next
);
630 /*********************************************************************
633 static float CDECL
unix_nextafterf(float num
, float next
)
635 return nextafterf(num
,next
);
638 /*********************************************************************
641 static double CDECL
unix_nexttoward(double num
, double next
)
643 #ifdef HAVE_NEXTTOWARD
644 return nexttoward(num
, next
);
646 FIXME("not implemented\n");
651 /*********************************************************************
654 static float CDECL
unix_nexttowardf(float num
, double next
)
656 #ifdef HAVE_NEXTTOWARDF
657 return nexttowardf(num
, next
);
659 FIXME("not implemented\n");
664 /*********************************************************************
667 static double CDECL
unix_pow( double x
, double y
)
672 /*********************************************************************
675 static float CDECL
unix_powf( float x
, float y
)
680 /*********************************************************************
683 static double CDECL
unix_remainder(double x
, double y
)
685 #ifdef HAVE_REMAINDER
686 return remainder(x
, y
);
688 FIXME( "not implemented\n" );
693 /*********************************************************************
696 static float CDECL
unix_remainderf(float x
, float y
)
698 #ifdef HAVE_REMAINDERF
699 return remainderf(x
, y
);
701 FIXME( "not implemented\n" );
706 /*********************************************************************
709 static double CDECL
unix_remquo(double x
, double y
, int *quo
)
712 return remquo(x
, y
, quo
);
714 FIXME( "not implemented\n" );
719 /*********************************************************************
722 static float CDECL
unix_remquof(float x
, float y
, int *quo
)
725 return remquof(x
, y
, quo
);
727 FIXME( "not implemented\n" );
732 /*********************************************************************
735 static double CDECL
unix_rint(double x
)
740 return x
>= 0 ? floor(x
+ 0.5) : ceil(x
- 0.5);
744 /*********************************************************************
747 static float CDECL
unix_rintf(float x
)
752 return x
>= 0 ? floorf(x
+ 0.5) : ceilf(x
- 0.5);
756 /*********************************************************************
759 static double CDECL
unix_round(double x
)
768 /*********************************************************************
771 static int CDECL
unix_lround(double x
)
776 return unix_round(x
);
780 /*********************************************************************
783 static double CDECL
unix_sin( double x
)
788 /*********************************************************************
791 static float CDECL
unix_sinf( float x
)
796 /*********************************************************************
799 static double CDECL
unix_sinh( double x
)
804 /*********************************************************************
807 static float CDECL
unix_sinhf( float x
)
812 /*********************************************************************
815 static double CDECL
unix_tan( double x
)
820 /*********************************************************************
823 static float CDECL
unix_tanf( float x
)
828 /*********************************************************************
831 static double CDECL
unix_tanh( double x
)
836 /*********************************************************************
839 static float CDECL
unix_tanhf( float x
)
844 /*********************************************************************
847 static double CDECL
unix_tgamma(double x
)
852 FIXME( "not implemented\n" );
857 /*********************************************************************
860 static double CDECL
unix_trunc(double x
)
865 return (x
> 0) ? floor(x
) : ceil(x
);
869 /*********************************************************************
872 static float CDECL
unix_truncf(float x
)
877 return unix_trunc(x
);
881 /*********************************************************************
884 static float CDECL
unix_tgammaf(float x
)
889 FIXME( "not implemented\n" );
894 static const struct unix_funcs funcs
=
979 NTSTATUS CDECL
__wine_init_unix_lib( HMODULE module
, DWORD reason
, const void *ptr_in
, void *ptr_out
)
981 if (reason
!= DLL_PROCESS_ATTACH
) return STATUS_SUCCESS
;
983 *(const struct unix_funcs
**)ptr_out
= &funcs
;
984 return STATUS_SUCCESS
;