2 * msvcrt.dll math functions
4 * Copyright 2000 Jon Griffiths
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 #include "wine/port.h"
24 #define __USE_ISOC9X 1
25 #define __USE_ISOC99 1
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
38 #define finitef(x) isfinite(x)
43 #define isnanf(x) isnan(x)
49 /* FIXME: Does not work with -NAN and -0. */
51 #define signbit(x) ((x) < 0)
54 typedef int (CDECL
*MSVCRT_matherr_func
)(struct MSVCRT__exception
*);
55 typedef double LDOUBLE
; /* long double is just a double */
57 static MSVCRT_matherr_func MSVCRT_default_matherr_func
= NULL
;
59 static BOOL sse2_supported
;
60 static BOOL sse2_enabled
;
62 void msvcrt_init_math(void)
64 sse2_supported
= sse2_enabled
= IsProcessorFeaturePresent( PF_XMMI64_INSTRUCTIONS_AVAILABLE
);
67 /*********************************************************************
68 * _set_SSE2_enable (MSVCRT.@)
70 int CDECL
MSVCRT__set_SSE2_enable(int flag
)
72 sse2_enabled
= flag
&& sse2_supported
;
77 /*********************************************************************
78 * _set_FMA3_enable (MSVCR120.@)
80 int CDECL
MSVCRT__set_FMA3_enable(int flag
)
82 FIXME("(%x) stub\n", flag
);
87 #if defined(__x86_64__) || defined(__arm__) || _MSVCR_VER>=120
89 /*********************************************************************
90 * _chgsignf (MSVCRT.@)
92 float CDECL
MSVCRT__chgsignf( float num
)
94 /* FIXME: +-infinity,Nan not tested */
98 /*********************************************************************
99 * _copysignf (MSVCRT.@)
101 float CDECL
MSVCRT__copysignf( float num
, float sign
)
104 return signbit(num
) ? num
: -num
;
105 return signbit(num
) ? -num
: num
;
108 /*********************************************************************
109 * _nextafterf (MSVCRT.@)
111 float CDECL
MSVCRT__nextafterf( float num
, float next
)
113 if (!finitef(num
) || !finitef(next
)) *MSVCRT__errno() = MSVCRT_EDOM
;
114 return nextafterf( num
, next
);
118 #if defined(__x86_64__) || defined(__arm__)
120 /*********************************************************************
121 * _finitef (MSVCRT.@)
123 int CDECL
MSVCRT__finitef( float num
)
125 return finitef(num
) != 0; /* See comment for _isnan() */
128 /*********************************************************************
131 INT CDECL
MSVCRT__isnanf( float num
)
133 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
134 * Do the same, as the result may be used in calculations
136 return isnanf(num
) != 0;
139 /*********************************************************************
142 float CDECL
MSVCRT__logbf( float num
)
144 if (!finitef(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
148 /*********************************************************************
149 * MSVCRT_acosf (MSVCRT.@)
151 float CDECL
MSVCRT_acosf( float x
)
153 if (x
< -1.0 || x
> 1.0 || !finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
154 /* glibc implements acos() as the FPU equivalent of atan2(sqrt(1 - x ^ 2), x).
155 * asin() uses a similar construction. This is bad because as x gets nearer to
156 * 1 the error in the expression "1 - x^2" can get relatively large due to
157 * cancellation. The sqrt() makes things worse. A safer way to calculate
158 * acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */
159 return atan2f(sqrtf((1 - x
) * (1 + x
)), x
);
162 /*********************************************************************
163 * MSVCRT_asinf (MSVCRT.@)
165 float CDECL
MSVCRT_asinf( float x
)
167 if (x
< -1.0 || x
> 1.0 || !finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
168 return atan2f(x
, sqrtf((1 - x
) * (1 + x
)));
171 /*********************************************************************
172 * MSVCRT_atanf (MSVCRT.@)
174 float CDECL
MSVCRT_atanf( float x
)
176 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
180 /*********************************************************************
181 * MSVCRT_atan2f (MSVCRT.@)
183 float CDECL
MSVCRT_atan2f( float x
, float y
)
185 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
189 /*********************************************************************
190 * MSVCRT_cosf (MSVCRT.@)
192 float CDECL
MSVCRT_cosf( float x
)
194 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
198 /*********************************************************************
199 * MSVCRT_coshf (MSVCRT.@)
201 float CDECL
MSVCRT_coshf( float x
)
203 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
207 /*********************************************************************
208 * MSVCRT_expf (MSVCRT.@)
210 float CDECL
MSVCRT_expf( float x
)
212 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
216 /*********************************************************************
217 * MSVCRT_fmodf (MSVCRT.@)
219 float CDECL
MSVCRT_fmodf( float x
, float y
)
221 if (!finitef(x
) || !finitef(y
)) *MSVCRT__errno() = MSVCRT_EDOM
;
225 /*********************************************************************
226 * MSVCRT_logf (MSVCRT.@)
228 float CDECL
MSVCRT_logf( float x
)
230 if (x
< 0.0 || !finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
231 if (x
== 0.0) *MSVCRT__errno() = MSVCRT_ERANGE
;
235 /*********************************************************************
236 * MSVCRT_log10f (MSVCRT.@)
238 float CDECL
MSVCRT_log10f( float x
)
240 if (x
< 0.0 || !finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
241 if (x
== 0.0) *MSVCRT__errno() = MSVCRT_ERANGE
;
245 /*********************************************************************
246 * MSVCRT_powf (MSVCRT.@)
248 float CDECL
MSVCRT_powf( float x
, float y
)
250 /* FIXME: If x < 0 and y is not integral, set EDOM */
252 if (!finitef(z
)) *MSVCRT__errno() = MSVCRT_EDOM
;
256 /*********************************************************************
257 * MSVCRT_sinf (MSVCRT.@)
259 float CDECL
MSVCRT_sinf( float x
)
261 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
265 /*********************************************************************
266 * MSVCRT_sinhf (MSVCRT.@)
268 float CDECL
MSVCRT_sinhf( float x
)
270 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
274 /*********************************************************************
275 * MSVCRT_sqrtf (MSVCRT.@)
277 float CDECL
MSVCRT_sqrtf( float x
)
279 if (x
< 0.0 || !finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
283 /*********************************************************************
284 * MSVCRT_tanf (MSVCRT.@)
286 float CDECL
MSVCRT_tanf( float x
)
288 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
292 /*********************************************************************
293 * MSVCRT_tanhf (MSVCRT.@)
295 float CDECL
MSVCRT_tanhf( float x
)
297 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
301 /*********************************************************************
304 float CDECL
MSVCRT_ceilf( float x
)
309 /*********************************************************************
312 float CDECL
MSVCRT_fabsf( float x
)
317 /*********************************************************************
320 float CDECL
MSVCRT_floorf( float x
)
325 /*********************************************************************
328 float CDECL
MSVCRT_frexpf( float x
, int *exp
)
330 return frexpf( x
, exp
);
333 /*********************************************************************
336 float CDECL
MSVCRT_modff( float x
, float *iptr
)
338 return modff( x
, iptr
);
343 /*********************************************************************
344 * MSVCRT_acos (MSVCRT.@)
346 double CDECL
MSVCRT_acos( double x
)
348 if (x
< -1.0 || x
> 1.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
349 /* glibc implements acos() as the FPU equivalent of atan2(sqrt(1 - x ^ 2), x).
350 * asin() uses a similar construction. This is bad because as x gets nearer to
351 * 1 the error in the expression "1 - x^2" can get relatively large due to
352 * cancellation. The sqrt() makes things worse. A safer way to calculate
353 * acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */
354 return atan2(sqrt((1 - x
) * (1 + x
)), x
);
357 /*********************************************************************
358 * MSVCRT_asin (MSVCRT.@)
360 double CDECL
MSVCRT_asin( double x
)
362 if (x
< -1.0 || x
> 1.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
363 return atan2(x
, sqrt((1 - x
) * (1 + x
)));
366 /*********************************************************************
367 * MSVCRT_atan (MSVCRT.@)
369 double CDECL
MSVCRT_atan( double x
)
371 if (isnan(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
375 /*********************************************************************
376 * MSVCRT_atan2 (MSVCRT.@)
378 double CDECL
MSVCRT_atan2( double x
, double y
)
380 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
384 /*********************************************************************
385 * MSVCRT_cos (MSVCRT.@)
387 double CDECL
MSVCRT_cos( double x
)
389 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
393 /*********************************************************************
394 * MSVCRT_cosh (MSVCRT.@)
396 double CDECL
MSVCRT_cosh( double x
)
398 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
402 /*********************************************************************
403 * MSVCRT_exp (MSVCRT.@)
405 double CDECL
MSVCRT_exp( double x
)
407 if (isnan(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
411 /*********************************************************************
412 * MSVCRT_fmod (MSVCRT.@)
414 double CDECL
MSVCRT_fmod( double x
, double y
)
416 if (!isfinite(x
) || !isfinite(y
)) *MSVCRT__errno() = MSVCRT_EDOM
;
420 /*********************************************************************
421 * MSVCRT_log (MSVCRT.@)
423 double CDECL
MSVCRT_log( double x
)
425 if (x
< 0.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
426 if (x
== 0.0) *MSVCRT__errno() = MSVCRT_ERANGE
;
430 /*********************************************************************
431 * MSVCRT_log10 (MSVCRT.@)
433 double CDECL
MSVCRT_log10( double x
)
435 if (x
< 0.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
436 if (x
== 0.0) *MSVCRT__errno() = MSVCRT_ERANGE
;
440 /*********************************************************************
441 * MSVCRT_pow (MSVCRT.@)
443 double CDECL
MSVCRT_pow( double x
, double y
)
445 /* FIXME: If x < 0 and y is not integral, set EDOM */
447 if (!isfinite(z
)) *MSVCRT__errno() = MSVCRT_EDOM
;
451 /*********************************************************************
452 * MSVCRT_sin (MSVCRT.@)
454 double CDECL
MSVCRT_sin( double x
)
456 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
460 /*********************************************************************
461 * MSVCRT_sinh (MSVCRT.@)
463 double CDECL
MSVCRT_sinh( double x
)
465 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
469 /*********************************************************************
470 * MSVCRT_sqrt (MSVCRT.@)
472 double CDECL
MSVCRT_sqrt( double x
)
474 if (x
< 0.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
478 /*********************************************************************
479 * MSVCRT_tan (MSVCRT.@)
481 double CDECL
MSVCRT_tan( double x
)
483 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
487 /*********************************************************************
488 * MSVCRT_tanh (MSVCRT.@)
490 double CDECL
MSVCRT_tanh( double x
)
492 if (isnan(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
497 #if defined(__GNUC__) && defined(__i386__)
499 #define FPU_DOUBLE(var) double var; \
500 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
501 #define FPU_DOUBLES(var1,var2) double var1,var2; \
502 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
503 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
505 /*********************************************************************
508 double CDECL
_CIacos(void)
511 return MSVCRT_acos(x
);
514 /*********************************************************************
517 double CDECL
_CIasin(void)
520 return MSVCRT_asin(x
);
523 /*********************************************************************
526 double CDECL
_CIatan(void)
529 return MSVCRT_atan(x
);
532 /*********************************************************************
533 * _CIatan2 (MSVCRT.@)
535 double CDECL
_CIatan2(void)
538 return MSVCRT_atan2(x
,y
);
541 /*********************************************************************
544 double CDECL
_CIcos(void)
547 return MSVCRT_cos(x
);
550 /*********************************************************************
553 double CDECL
_CIcosh(void)
556 return MSVCRT_cosh(x
);
559 /*********************************************************************
562 double CDECL
_CIexp(void)
565 return MSVCRT_exp(x
);
568 /*********************************************************************
571 double CDECL
_CIfmod(void)
574 return MSVCRT_fmod(x
,y
);
577 /*********************************************************************
580 double CDECL
_CIlog(void)
583 return MSVCRT_log(x
);
586 /*********************************************************************
587 * _CIlog10 (MSVCRT.@)
589 double CDECL
_CIlog10(void)
592 return MSVCRT_log10(x
);
595 /*********************************************************************
598 double CDECL
_CIpow(void)
601 return MSVCRT_pow(x
,y
);
604 /*********************************************************************
607 double CDECL
_CIsin(void)
610 return MSVCRT_sin(x
);
613 /*********************************************************************
616 double CDECL
_CIsinh(void)
619 return MSVCRT_sinh(x
);
622 /*********************************************************************
625 double CDECL
_CIsqrt(void)
628 return MSVCRT_sqrt(x
);
631 /*********************************************************************
634 double CDECL
_CItan(void)
637 return MSVCRT_tan(x
);
640 /*********************************************************************
643 double CDECL
_CItanh(void)
646 return MSVCRT_tanh(x
);
649 /*********************************************************************
652 LONGLONG CDECL
MSVCRT__ftol(void)
658 #endif /* defined(__GNUC__) && defined(__i386__) */
660 /*********************************************************************
661 * _fpclass (MSVCRT.@)
663 int CDECL
MSVCRT__fpclass(double num
)
665 #if defined(HAVE_FPCLASS) || defined(fpclass)
666 switch (fpclass( num
))
668 case FP_SNAN
: return MSVCRT__FPCLASS_SNAN
;
669 case FP_QNAN
: return MSVCRT__FPCLASS_QNAN
;
670 case FP_NINF
: return MSVCRT__FPCLASS_NINF
;
671 case FP_PINF
: return MSVCRT__FPCLASS_PINF
;
672 case FP_NDENORM
: return MSVCRT__FPCLASS_ND
;
673 case FP_PDENORM
: return MSVCRT__FPCLASS_PD
;
674 case FP_NZERO
: return MSVCRT__FPCLASS_NZ
;
675 case FP_PZERO
: return MSVCRT__FPCLASS_PZ
;
676 case FP_NNORM
: return MSVCRT__FPCLASS_NN
;
677 case FP_PNORM
: return MSVCRT__FPCLASS_PN
;
678 default: return MSVCRT__FPCLASS_PN
;
680 #elif defined (fpclassify)
681 switch (fpclassify( num
))
683 case FP_NAN
: return MSVCRT__FPCLASS_QNAN
;
684 case FP_INFINITE
: return signbit(num
) ? MSVCRT__FPCLASS_NINF
: MSVCRT__FPCLASS_PINF
;
685 case FP_SUBNORMAL
: return signbit(num
) ?MSVCRT__FPCLASS_ND
: MSVCRT__FPCLASS_PD
;
686 case FP_ZERO
: return signbit(num
) ? MSVCRT__FPCLASS_NZ
: MSVCRT__FPCLASS_PZ
;
688 return signbit(num
) ? MSVCRT__FPCLASS_NN
: MSVCRT__FPCLASS_PN
;
691 return MSVCRT__FPCLASS_QNAN
;
692 return num
== 0.0 ? MSVCRT__FPCLASS_PZ
: (num
< 0 ? MSVCRT__FPCLASS_NN
: MSVCRT__FPCLASS_PN
);
696 /*********************************************************************
699 unsigned int CDECL
_rotl(unsigned int num
, int shift
)
702 return (num
<< shift
) | (num
>> (32-shift
));
705 /*********************************************************************
708 MSVCRT_ulong CDECL
MSVCRT__lrotl(MSVCRT_ulong num
, int shift
)
711 return (num
<< shift
) | (num
>> (32-shift
));
714 /*********************************************************************
717 MSVCRT_ulong CDECL
MSVCRT__lrotr(MSVCRT_ulong num
, int shift
)
720 return (num
>> shift
) | (num
<< (32-shift
));
723 /*********************************************************************
726 unsigned int CDECL
_rotr(unsigned int num
, int shift
)
729 return (num
>> shift
) | (num
<< (32-shift
));
732 /*********************************************************************
735 unsigned __int64 CDECL
_rotl64(unsigned __int64 num
, int shift
)
738 return (num
<< shift
) | (num
>> (64-shift
));
741 /*********************************************************************
744 unsigned __int64 CDECL
_rotr64(unsigned __int64 num
, int shift
)
747 return (num
>> shift
) | (num
<< (64-shift
));
750 /*********************************************************************
753 int CDECL
MSVCRT_abs( int n
)
755 return n
>= 0 ? n
: -n
;
758 /*********************************************************************
761 MSVCRT_long CDECL
MSVCRT_labs( MSVCRT_long n
)
763 return n
>= 0 ? n
: -n
;
766 /*********************************************************************
769 MSVCRT_longlong CDECL
MSVCRT_llabs( MSVCRT_longlong n
)
771 return n
>= 0 ? n
: -n
;
774 /*********************************************************************
777 __int64 CDECL
_abs64( __int64 n
)
779 return n
>= 0 ? n
: -n
;
782 /*********************************************************************
785 double CDECL
MSVCRT__logb(double num
)
787 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
791 /*********************************************************************
794 double CDECL
_hypot(double x
, double y
)
796 /* FIXME: errno handling */
797 return hypot( x
, y
);
800 /*********************************************************************
803 float CDECL
MSVCRT__hypotf(float x
, float y
)
805 /* FIXME: errno handling */
806 return hypotf( x
, y
);
809 /*********************************************************************
812 double CDECL
MSVCRT_ceil( double x
)
817 /*********************************************************************
820 double CDECL
MSVCRT_floor( double x
)
825 /*********************************************************************
828 double CDECL
MSVCRT_fabs( double x
)
833 /*********************************************************************
836 double CDECL
MSVCRT_frexp( double x
, int *exp
)
838 return frexp( x
, exp
);
841 /*********************************************************************
844 double CDECL
MSVCRT_modf( double x
, double *iptr
)
846 return modf( x
, iptr
);
849 /*********************************************************************
850 * _matherr (MSVCRT.@)
852 int CDECL
MSVCRT__matherr(struct MSVCRT__exception
*e
)
855 TRACE("(%p = %d, %s, %g %g %g)\n",e
, e
->type
, e
->name
, e
->arg1
, e
->arg2
,
859 if (MSVCRT_default_matherr_func
)
860 return MSVCRT_default_matherr_func(e
);
861 ERR(":Unhandled math error!\n");
865 /*********************************************************************
866 * __setusermatherr (MSVCRT.@)
868 void CDECL
MSVCRT___setusermatherr(MSVCRT_matherr_func func
)
870 MSVCRT_default_matherr_func
= func
;
871 TRACE(":new matherr handler %p\n", func
);
874 /**********************************************************************
875 * _statusfp2 (MSVCRT.@)
877 * Not exported by native msvcrt, added in msvcr80.
879 #if defined(__i386__) || defined(__x86_64__)
880 void CDECL
_statusfp2( unsigned int *x86_sw
, unsigned int *sse2_sw
)
884 unsigned long fpword
;
888 __asm__
__volatile__( "fstsw %0" : "=m" (fpword
) );
890 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
891 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
892 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
893 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
894 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
895 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
899 if (!sse2_sw
) return;
903 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
905 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
906 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
907 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
908 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
909 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
910 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
915 FIXME( "not implemented\n" );
920 /**********************************************************************
921 * _statusfp (MSVCRT.@)
923 unsigned int CDECL
_statusfp(void)
925 #if defined(__i386__) || defined(__x86_64__)
926 unsigned int x86_sw
, sse2_sw
;
928 _statusfp2( &x86_sw
, &sse2_sw
);
929 /* FIXME: there's no definition for ambiguous status, just return all status bits for now */
930 return x86_sw
| sse2_sw
;
932 FIXME( "not implemented\n" );
937 /*********************************************************************
938 * _clearfp (MSVCRT.@)
940 unsigned int CDECL
_clearfp(void)
942 unsigned int flags
= 0;
943 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
944 unsigned long fpword
;
946 __asm__
__volatile__( "fnstsw %0; fnclex" : "=m" (fpword
) );
947 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
948 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
949 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
950 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
951 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
952 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
956 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
957 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
958 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
959 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
960 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
961 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
962 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
964 __asm__
__volatile__( "ldmxcsr %0" : : "m" (fpword
) );
967 FIXME( "not implemented\n" );
972 /*********************************************************************
973 * __fpecode (MSVCRT.@)
975 int * CDECL
__fpecode(void)
977 return &msvcrt_get_thread_data()->fpecode
;
980 /*********************************************************************
983 double CDECL
MSVCRT_ldexp(double num
, MSVCRT_long exp
)
985 double z
= ldexp(num
,exp
);
988 *MSVCRT__errno() = MSVCRT_ERANGE
;
989 else if (z
== 0 && signbit(z
))
990 z
= 0.0; /* Convert -0 -> +0 */
994 /*********************************************************************
997 double CDECL
MSVCRT__cabs(struct MSVCRT__complex num
)
999 return sqrt(num
.x
* num
.x
+ num
.y
* num
.y
);
1002 /*********************************************************************
1003 * _chgsign (MSVCRT.@)
1005 double CDECL
MSVCRT__chgsign(double num
)
1007 /* FIXME: +-infinity,Nan not tested */
1011 /*********************************************************************
1012 * __control87_2 (MSVCRT.@)
1014 * Not exported by native msvcrt, added in msvcr80.
1016 #if defined(__i386__) || defined(__x86_64__)
1017 int CDECL
__control87_2( unsigned int newval
, unsigned int mask
,
1018 unsigned int *x86_cw
, unsigned int *sse2_cw
)
1021 unsigned long fpword
;
1026 __asm__
__volatile__( "fstcw %0" : "=m" (fpword
) );
1028 /* Convert into mask constants */
1030 if (fpword
& 0x1) flags
|= MSVCRT__EM_INVALID
;
1031 if (fpword
& 0x2) flags
|= MSVCRT__EM_DENORMAL
;
1032 if (fpword
& 0x4) flags
|= MSVCRT__EM_ZERODIVIDE
;
1033 if (fpword
& 0x8) flags
|= MSVCRT__EM_OVERFLOW
;
1034 if (fpword
& 0x10) flags
|= MSVCRT__EM_UNDERFLOW
;
1035 if (fpword
& 0x20) flags
|= MSVCRT__EM_INEXACT
;
1036 switch (fpword
& 0xc00)
1038 case 0xc00: flags
|= MSVCRT__RC_UP
|MSVCRT__RC_DOWN
; break;
1039 case 0x800: flags
|= MSVCRT__RC_UP
; break;
1040 case 0x400: flags
|= MSVCRT__RC_DOWN
; break;
1042 switch (fpword
& 0x300)
1044 case 0x0: flags
|= MSVCRT__PC_24
; break;
1045 case 0x200: flags
|= MSVCRT__PC_53
; break;
1046 case 0x300: flags
|= MSVCRT__PC_64
; break;
1048 if (fpword
& 0x1000) flags
|= MSVCRT__IC_AFFINE
;
1050 TRACE( "x86 flags=%08x newval=%08x mask=%08x\n", flags
, newval
, mask
);
1053 flags
= (flags
& ~mask
) | (newval
& mask
);
1055 /* Convert (masked) value back to fp word */
1057 if (flags
& MSVCRT__EM_INVALID
) fpword
|= 0x1;
1058 if (flags
& MSVCRT__EM_DENORMAL
) fpword
|= 0x2;
1059 if (flags
& MSVCRT__EM_ZERODIVIDE
) fpword
|= 0x4;
1060 if (flags
& MSVCRT__EM_OVERFLOW
) fpword
|= 0x8;
1061 if (flags
& MSVCRT__EM_UNDERFLOW
) fpword
|= 0x10;
1062 if (flags
& MSVCRT__EM_INEXACT
) fpword
|= 0x20;
1063 switch (flags
& MSVCRT__MCW_RC
)
1065 case MSVCRT__RC_UP
|MSVCRT__RC_DOWN
: fpword
|= 0xc00; break;
1066 case MSVCRT__RC_UP
: fpword
|= 0x800; break;
1067 case MSVCRT__RC_DOWN
: fpword
|= 0x400; break;
1069 switch (flags
& MSVCRT__MCW_PC
)
1071 case MSVCRT__PC_64
: fpword
|= 0x300; break;
1072 case MSVCRT__PC_53
: fpword
|= 0x200; break;
1073 case MSVCRT__PC_24
: fpword
|= 0x0; break;
1075 if (flags
& MSVCRT__IC_AFFINE
) fpword
|= 0x1000;
1077 __asm__
__volatile__( "fldcw %0" : : "m" (fpword
) );
1082 if (!sse2_cw
) return 1;
1086 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
1088 /* Convert into mask constants */
1090 if (fpword
& 0x80) flags
|= MSVCRT__EM_INVALID
;
1091 if (fpword
& 0x100) flags
|= MSVCRT__EM_DENORMAL
;
1092 if (fpword
& 0x200) flags
|= MSVCRT__EM_ZERODIVIDE
;
1093 if (fpword
& 0x400) flags
|= MSVCRT__EM_OVERFLOW
;
1094 if (fpword
& 0x800) flags
|= MSVCRT__EM_UNDERFLOW
;
1095 if (fpword
& 0x1000) flags
|= MSVCRT__EM_INEXACT
;
1096 switch (fpword
& 0x6000)
1098 case 0x6000: flags
|= MSVCRT__RC_UP
|MSVCRT__RC_DOWN
; break;
1099 case 0x4000: flags
|= MSVCRT__RC_UP
; break;
1100 case 0x2000: flags
|= MSVCRT__RC_DOWN
; break;
1102 switch (fpword
& 0x8040)
1104 case 0x0040: flags
|= MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS
; break;
1105 case 0x8000: flags
|= MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS
; break;
1106 case 0x8040: flags
|= MSVCRT__DN_FLUSH
; break;
1109 TRACE( "sse2 flags=%08x newval=%08x mask=%08x\n", flags
, newval
, mask
);
1112 flags
= (flags
& ~mask
) | (newval
& mask
);
1114 /* Convert (masked) value back to fp word */
1116 if (flags
& MSVCRT__EM_INVALID
) fpword
|= 0x80;
1117 if (flags
& MSVCRT__EM_DENORMAL
) fpword
|= 0x100;
1118 if (flags
& MSVCRT__EM_ZERODIVIDE
) fpword
|= 0x200;
1119 if (flags
& MSVCRT__EM_OVERFLOW
) fpword
|= 0x400;
1120 if (flags
& MSVCRT__EM_UNDERFLOW
) fpword
|= 0x800;
1121 if (flags
& MSVCRT__EM_INEXACT
) fpword
|= 0x1000;
1122 switch (flags
& MSVCRT__MCW_RC
)
1124 case MSVCRT__RC_UP
|MSVCRT__RC_DOWN
: fpword
|= 0x6000; break;
1125 case MSVCRT__RC_UP
: fpword
|= 0x4000; break;
1126 case MSVCRT__RC_DOWN
: fpword
|= 0x2000; break;
1128 switch (flags
& MSVCRT__MCW_DN
)
1130 case MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS
: fpword
|= 0x0040; break;
1131 case MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS
: fpword
|= 0x8000; break;
1132 case MSVCRT__DN_FLUSH
: fpword
|= 0x8040; break;
1134 __asm__
__volatile__( "ldmxcsr %0" : : "m" (fpword
) );
1142 FIXME( "not implemented\n" );
1148 /*********************************************************************
1149 * _control87 (MSVCRT.@)
1151 unsigned int CDECL
_control87(unsigned int newval
, unsigned int mask
)
1153 #if defined(__i386__) || defined(__x86_64__)
1154 unsigned int x86_cw
, sse2_cw
;
1156 __control87_2( newval
, mask
, &x86_cw
, &sse2_cw
);
1158 if ((x86_cw
^ sse2_cw
) & (MSVCRT__MCW_EM
| MSVCRT__MCW_RC
)) x86_cw
|= MSVCRT__EM_AMBIGUOUS
;
1161 FIXME( "not implemented\n" );
1166 /*********************************************************************
1167 * _controlfp (MSVCRT.@)
1169 unsigned int CDECL
_controlfp(unsigned int newval
, unsigned int mask
)
1171 return _control87( newval
, mask
& ~MSVCRT__EM_DENORMAL
);
1174 /*********************************************************************
1175 * _set_controlfp (MSVCRT.@)
1177 void CDECL
_set_controlfp( unsigned int newval
, unsigned int mask
)
1179 _controlfp( newval
, mask
);
1182 /*********************************************************************
1183 * _controlfp_s (MSVCRT.@)
1185 int CDECL
_controlfp_s(unsigned int *cur
, unsigned int newval
, unsigned int mask
)
1187 static const unsigned int all_flags
= (MSVCRT__MCW_EM
| MSVCRT__MCW_IC
| MSVCRT__MCW_RC
|
1188 MSVCRT__MCW_PC
| MSVCRT__MCW_DN
);
1191 if (!MSVCRT_CHECK_PMT( !(newval
& mask
& ~all_flags
) ))
1193 if (cur
) *cur
= _controlfp( 0, 0 ); /* retrieve it anyway */
1194 return MSVCRT_EINVAL
;
1196 val
= _controlfp( newval
, mask
);
1197 if (cur
) *cur
= val
;
1201 /*********************************************************************
1202 * fegetenv (MSVCR120.@)
1204 int CDECL
MSVCRT_fegetenv(MSVCRT_fenv_t
*env
)
1206 env
->control
= _controlfp(0, 0) & (MSVCRT__EM_INEXACT
| MSVCRT__EM_UNDERFLOW
|
1207 MSVCRT__EM_OVERFLOW
| MSVCRT__EM_ZERODIVIDE
| MSVCRT__EM_INVALID
);
1208 env
->status
= _statusfp();
1212 /*********************************************************************
1213 * __fpe_flt_rounds (UCRTBASE.@)
1215 int CDECL
__fpe_flt_rounds(void)
1217 unsigned int fpc
= _controlfp(0, 0) & MSVCRT__RC_CHOP
;
1222 case MSVCRT__RC_CHOP
: return 0;
1223 case MSVCRT__RC_NEAR
: return 1;
1225 case MSVCRT__RC_UP
: return 3;
1228 case MSVCRT__RC_UP
: return 2;
1234 /*********************************************************************
1235 * _copysign (MSVCRT.@)
1237 double CDECL
MSVCRT__copysign(double num
, double sign
)
1240 return signbit(num
) ? num
: -num
;
1241 return signbit(num
) ? -num
: num
;
1244 /*********************************************************************
1245 * _finite (MSVCRT.@)
1247 int CDECL
MSVCRT__finite(double num
)
1249 return isfinite(num
) != 0; /* See comment for _isnan() */
1252 /*********************************************************************
1253 * _fpreset (MSVCRT.@)
1255 void CDECL
_fpreset(void)
1257 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1258 const unsigned int x86_cw
= 0x27f;
1259 __asm__
__volatile__( "fninit; fldcw %0" : : "m" (x86_cw
) );
1262 const unsigned long sse2_cw
= 0x1f80;
1263 __asm__
__volatile__( "ldmxcsr %0" : : "m" (sse2_cw
) );
1266 FIXME( "not implemented\n" );
1270 /*********************************************************************
1271 * fesetenv (MSVCR120.@)
1273 int CDECL
MSVCRT_fesetenv(const MSVCRT_fenv_t
*env
)
1275 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1283 DWORD instruction_pointer
;
1291 TRACE( "(%p)\n", env
);
1293 if (!env
->control
&& !env
->status
) {
1298 __asm__
__volatile__( "fnstenv %0" : "=m" (fenv
) );
1300 fenv
.control_word
&= ~0x3d;
1301 if (env
->control
& MSVCRT__EM_INVALID
) fenv
.control_word
|= 0x1;
1302 if (env
->control
& MSVCRT__EM_ZERODIVIDE
) fenv
.control_word
|= 0x4;
1303 if (env
->control
& MSVCRT__EM_OVERFLOW
) fenv
.control_word
|= 0x8;
1304 if (env
->control
& MSVCRT__EM_UNDERFLOW
) fenv
.control_word
|= 0x10;
1305 if (env
->control
& MSVCRT__EM_INEXACT
) fenv
.control_word
|= 0x20;
1307 fenv
.status_word
&= ~0x3d;
1308 if (env
->status
& MSVCRT__SW_INVALID
) fenv
.status_word
|= 0x1;
1309 if (env
->status
& MSVCRT__SW_ZERODIVIDE
) fenv
.status_word
|= 0x4;
1310 if (env
->status
& MSVCRT__SW_OVERFLOW
) fenv
.status_word
|= 0x8;
1311 if (env
->status
& MSVCRT__SW_UNDERFLOW
) fenv
.status_word
|= 0x10;
1312 if (env
->status
& MSVCRT__SW_INEXACT
) fenv
.status_word
|= 0x20;
1314 __asm__
__volatile__( "fldenv %0" : : "m" (fenv
) : "st", "st(1)",
1315 "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)" );
1321 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
1323 if (env
->control
& MSVCRT__EM_INVALID
) fpword
|= 0x80;
1324 if (env
->control
& MSVCRT__EM_ZERODIVIDE
) fpword
|= 0x200;
1325 if (env
->control
& MSVCRT__EM_OVERFLOW
) fpword
|= 0x400;
1326 if (env
->control
& MSVCRT__EM_UNDERFLOW
) fpword
|= 0x800;
1327 if (env
->control
& MSVCRT__EM_INEXACT
) fpword
|= 0x1000;
1328 __asm__
__volatile__( "ldmxcsr %0" : : "m" (fpword
) );
1333 FIXME( "not implemented\n" );
1338 /*********************************************************************
1341 INT CDECL
MSVCRT__isnan(double num
)
1343 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
1344 * Do the same, as the result may be used in calculations
1346 return isnan(num
) != 0;
1349 /*********************************************************************
1352 double CDECL
MSVCRT__j0(double num
)
1354 /* FIXME: errno handling */
1358 /*********************************************************************
1361 double CDECL
MSVCRT__j1(double num
)
1363 /* FIXME: errno handling */
1367 /*********************************************************************
1370 double CDECL
MSVCRT__jn(int n
, double num
)
1372 /* FIXME: errno handling */
1376 /*********************************************************************
1379 double CDECL
MSVCRT__y0(double num
)
1382 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
1384 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
1386 *MSVCRT__errno() = MSVCRT_EDOM
;
1392 /*********************************************************************
1395 double CDECL
MSVCRT__y1(double num
)
1398 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
1400 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
1402 *MSVCRT__errno() = MSVCRT_EDOM
;
1408 /*********************************************************************
1411 double CDECL
MSVCRT__yn(int order
, double num
)
1414 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
1415 retval
= yn(order
,num
);
1416 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
1418 *MSVCRT__errno() = MSVCRT_EDOM
;
1424 /*********************************************************************
1425 * _nearbyint (MSVCRT.@)
1427 double CDECL
MSVCRT_nearbyint(double num
)
1429 #ifdef HAVE_NEARBYINT
1430 return nearbyint(num
);
1432 return num
>= 0 ? floor(num
+ 0.5) : ceil(num
- 0.5);
1436 /*********************************************************************
1437 * _nearbyintf (MSVCRT.@)
1439 float CDECL
MSVCRT_nearbyintf(float num
)
1441 #ifdef HAVE_NEARBYINTF
1442 return nearbyintf(num
);
1444 return MSVCRT_nearbyint(num
);
1448 /*********************************************************************
1449 * _nextafter (MSVCRT.@)
1451 double CDECL
MSVCRT__nextafter(double num
, double next
)
1454 if (!isfinite(num
) || !isfinite(next
)) *MSVCRT__errno() = MSVCRT_EDOM
;
1455 retval
= nextafter(num
,next
);
1459 /*********************************************************************
1462 char * CDECL
MSVCRT__ecvt( double number
, int ndigits
, int *decpt
, int *sign
)
1465 thread_data_t
*data
= msvcrt_get_thread_data();
1466 /* FIXME: check better for overflow (native supports over 300 chars) */
1467 ndigits
= min( ndigits
, 80 - 7); /* 7 : space for dec point, 1 for "e",
1468 * 4 for exponent and one for
1469 * terminating '\0' */
1470 if (!data
->efcvt_buffer
)
1471 data
->efcvt_buffer
= MSVCRT_malloc( 80 ); /* ought to be enough */
1478 /* handle cases with zero ndigits or less */
1480 if( prec
< 1) prec
= 2;
1481 len
= snprintf(data
->efcvt_buffer
, 80, "%.*le", prec
- 1, number
);
1482 /* take the decimal "point away */
1484 memmove( data
->efcvt_buffer
+ 1, data
->efcvt_buffer
+ 2, len
- 1 );
1485 /* take the exponential "e" out */
1486 data
->efcvt_buffer
[ prec
] = '\0';
1487 /* read the exponent */
1488 sscanf( data
->efcvt_buffer
+ prec
+ 1, "%d", decpt
);
1490 /* adjust for some border cases */
1491 if( data
->efcvt_buffer
[0] == '0')/* value is zero */
1493 /* handle cases with zero ndigits or less */
1495 if( data
->efcvt_buffer
[ 0] >= '5')
1497 data
->efcvt_buffer
[ 0] = '\0';
1499 TRACE("out=\"%s\"\n",data
->efcvt_buffer
);
1500 return data
->efcvt_buffer
;
1503 /*********************************************************************
1504 * _ecvt_s (MSVCRT.@)
1506 int CDECL
MSVCRT__ecvt_s( char *buffer
, MSVCRT_size_t length
, double number
, int ndigits
, int *decpt
, int *sign
)
1510 const char infret
[] = "1#INF";
1512 if (!MSVCRT_CHECK_PMT(buffer
!= NULL
)) return MSVCRT_EINVAL
;
1513 if (!MSVCRT_CHECK_PMT(decpt
!= NULL
)) return MSVCRT_EINVAL
;
1514 if (!MSVCRT_CHECK_PMT(sign
!= NULL
)) return MSVCRT_EINVAL
;
1515 if (!MSVCRT_CHECK_PMT_ERR( length
> 2, MSVCRT_ERANGE
)) return MSVCRT_ERANGE
;
1516 if (!MSVCRT_CHECK_PMT_ERR(ndigits
< (int)length
- 1, MSVCRT_ERANGE
)) return MSVCRT_ERANGE
;
1518 /* special case - inf */
1519 if(number
== HUGE_VAL
|| number
== -HUGE_VAL
)
1521 memset(buffer
, '0', ndigits
);
1522 memcpy(buffer
, infret
, min(ndigits
, sizeof(infret
) - 1 ) );
1523 buffer
[ndigits
] = '\0';
1525 if(number
== -HUGE_VAL
)
1531 /* handle cases with zero ndigits or less */
1533 if( prec
< 1) prec
= 2;
1534 result
= MSVCRT_malloc(prec
+ 7);
1541 len
= snprintf(result
, prec
+ 7, "%.*le", prec
- 1, number
);
1542 /* take the decimal "point away */
1544 memmove( result
+ 1, result
+ 2, len
- 1 );
1545 /* take the exponential "e" out */
1546 result
[ prec
] = '\0';
1547 /* read the exponent */
1548 sscanf( result
+ prec
+ 1, "%d", decpt
);
1550 /* adjust for some border cases */
1551 if( result
[0] == '0')/* value is zero */
1553 /* handle cases with zero ndigits or less */
1555 if( result
[ 0] >= '5')
1559 memcpy( buffer
, result
, max(ndigits
+ 1, 1) );
1560 MSVCRT_free( result
);
1564 /***********************************************************************
1567 char * CDECL
MSVCRT__fcvt( double number
, int ndigits
, int *decpt
, int *sign
)
1569 thread_data_t
*data
= msvcrt_get_thread_data();
1570 int stop
, dec1
, dec2
;
1571 char *ptr1
, *ptr2
, *first
;
1572 char buf
[80]; /* ought to be enough */
1574 if (!data
->efcvt_buffer
)
1575 data
->efcvt_buffer
= MSVCRT_malloc( 80 ); /* ought to be enough */
1583 stop
= snprintf(buf
, 80, "%.*f", ndigits
< 0 ? 0 : ndigits
, number
);
1585 ptr2
= data
->efcvt_buffer
;
1590 /* For numbers below the requested resolution, work out where
1591 the decimal point will be rather than finding it in the string */
1592 if (number
< 1.0 && number
> 0.0) {
1593 dec2
= log10(number
+ 1e-10);
1594 if (-dec2
<= ndigits
) dec2
= 0;
1597 /* If requested digits is zero or less, we will need to truncate
1598 * the returned string */
1603 while (*ptr1
== '0') ptr1
++; /* Skip leading zeroes */
1604 while (*ptr1
!= '\0' && *ptr1
!= '.') {
1605 if (!first
) first
= ptr2
;
1606 if ((ptr1
- buf
) < stop
) {
1617 while (*ptr1
== '0') { /* Process leading zeroes */
1622 while (*ptr1
!= '\0') {
1623 if (!first
) first
= ptr2
;
1630 /* We never found a non-zero digit, then our number is either
1631 * smaller than the requested precision, or 0.0 */
1636 first
= data
->efcvt_buffer
;
1641 *decpt
= dec2
? dec2
: dec1
;
1645 /***********************************************************************
1646 * _fcvt_s (MSVCRT.@)
1648 int CDECL
MSVCRT__fcvt_s(char* outbuffer
, MSVCRT_size_t size
, double number
, int ndigits
, int *decpt
, int *sign
)
1650 int stop
, dec1
, dec2
;
1651 char *ptr1
, *ptr2
, *first
;
1652 char buf
[80]; /* ought to be enough */
1654 if (!outbuffer
|| !decpt
|| !sign
|| size
== 0)
1656 *MSVCRT__errno() = MSVCRT_EINVAL
;
1657 return MSVCRT_EINVAL
;
1666 stop
= snprintf(buf
, 80, "%.*f", ndigits
< 0 ? 0 : ndigits
, number
);
1673 /* For numbers below the requested resolution, work out where
1674 the decimal point will be rather than finding it in the string */
1675 if (number
< 1.0 && number
> 0.0) {
1676 dec2
= log10(number
+ 1e-10);
1677 if (-dec2
<= ndigits
) dec2
= 0;
1680 /* If requested digits is zero or less, we will need to truncate
1681 * the returned string */
1686 while (*ptr1
== '0') ptr1
++; /* Skip leading zeroes */
1687 while (*ptr1
!= '\0' && *ptr1
!= '.') {
1688 if (!first
) first
= ptr2
;
1689 if ((ptr1
- buf
) < stop
) {
1703 while (*ptr1
== '0') { /* Process leading zeroes */
1704 if (number
== 0.0 && size
> 1) {
1712 while (*ptr1
!= '\0') {
1713 if (!first
) first
= ptr2
;
1723 /* We never found a non-zero digit, then our number is either
1724 * smaller than the requested precision, or 0.0 */
1725 if (!first
&& (number
<= 0.0))
1728 *decpt
= dec2
? dec2
: dec1
;
1732 /***********************************************************************
1735 char * CDECL
MSVCRT__gcvt( double number
, int ndigit
, char *buff
)
1738 *MSVCRT__errno() = MSVCRT_EINVAL
;
1743 *MSVCRT__errno() = MSVCRT_ERANGE
;
1747 MSVCRT_sprintf(buff
, "%.*g", ndigit
, number
);
1751 /***********************************************************************
1752 * _gcvt_s (MSVCRT.@)
1754 int CDECL
MSVCRT__gcvt_s(char *buff
, MSVCRT_size_t size
, double number
, int digits
)
1759 *MSVCRT__errno() = MSVCRT_EINVAL
;
1760 return MSVCRT_EINVAL
;
1763 if( digits
<0 || digits
>=size
) {
1767 *MSVCRT__errno() = MSVCRT_ERANGE
;
1768 return MSVCRT_ERANGE
;
1771 len
= MSVCRT__scprintf("%.*g", digits
, number
);
1774 *MSVCRT__errno() = MSVCRT_ERANGE
;
1775 return MSVCRT_ERANGE
;
1778 MSVCRT_sprintf(buff
, "%.*g", digits
, number
);
1782 #include <stdlib.h> /* div_t, ldiv_t */
1784 /*********************************************************************
1787 * [i386] Windows binary compatible - returns the struct in eax/edx.
1790 unsigned __int64 CDECL
MSVCRT_div(int num
, int denom
)
1792 div_t dt
= div(num
,denom
);
1793 return ((unsigned __int64
)dt
.rem
<< 32) | (unsigned int)dt
.quot
;
1796 /*********************************************************************
1799 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
1801 MSVCRT_div_t CDECL
MSVCRT_div(int num
, int denom
)
1803 div_t dt
= div(num
,denom
);
1811 #endif /* ifdef __i386__ */
1814 /*********************************************************************
1817 * [i386] Windows binary compatible - returns the struct in eax/edx.
1820 unsigned __int64 CDECL
MSVCRT_ldiv(MSVCRT_long num
, MSVCRT_long denom
)
1822 ldiv_t ldt
= ldiv(num
,denom
);
1823 return ((unsigned __int64
)ldt
.rem
<< 32) | (MSVCRT_ulong
)ldt
.quot
;
1826 /*********************************************************************
1829 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
1831 MSVCRT_ldiv_t CDECL
MSVCRT_ldiv(MSVCRT_long num
, MSVCRT_long denom
)
1833 ldiv_t result
= ldiv(num
,denom
);
1836 ret
.quot
= result
.quot
;
1837 ret
.rem
= result
.rem
;
1841 #endif /* ifdef __i386__ */
1843 /*********************************************************************
1846 MSVCRT_lldiv_t CDECL
MSVCRT_lldiv(MSVCRT_longlong num
, MSVCRT_longlong denom
)
1850 ret
.quot
= num
/ denom
;
1851 ret
.rem
= num
% denom
;
1858 /*********************************************************************
1859 * _adjust_fdiv (MSVCRT.@)
1860 * Used by the MSVC compiler to work around the Pentium FDIV bug.
1862 int MSVCRT__adjust_fdiv
= 0;
1864 /***********************************************************************
1865 * _adj_fdiv_m16i (MSVCRT.@)
1868 * I _think_ this function is intended to work around the Pentium
1871 void __stdcall
_adj_fdiv_m16i( short arg
)
1873 TRACE("(): stub\n");
1876 /***********************************************************************
1877 * _adj_fdiv_m32 (MSVCRT.@)
1880 * I _think_ this function is intended to work around the Pentium
1883 void __stdcall
_adj_fdiv_m32( unsigned int arg
)
1885 TRACE("(): stub\n");
1888 /***********************************************************************
1889 * _adj_fdiv_m32i (MSVCRT.@)
1892 * I _think_ this function is intended to work around the Pentium
1895 void __stdcall
_adj_fdiv_m32i( int arg
)
1897 TRACE("(): stub\n");
1900 /***********************************************************************
1901 * _adj_fdiv_m64 (MSVCRT.@)
1904 * I _think_ this function is intended to work around the Pentium
1907 void __stdcall
_adj_fdiv_m64( unsigned __int64 arg
)
1909 TRACE("(): stub\n");
1912 /***********************************************************************
1913 * _adj_fdiv_r (MSVCRT.@)
1915 * This function is likely to have the wrong number of arguments.
1918 * I _think_ this function is intended to work around the Pentium
1921 void _adj_fdiv_r(void)
1923 TRACE("(): stub\n");
1926 /***********************************************************************
1927 * _adj_fdivr_m16i (MSVCRT.@)
1930 * I _think_ this function is intended to work around the Pentium
1933 void __stdcall
_adj_fdivr_m16i( short arg
)
1935 TRACE("(): stub\n");
1938 /***********************************************************************
1939 * _adj_fdivr_m32 (MSVCRT.@)
1942 * I _think_ this function is intended to work around the Pentium
1945 void __stdcall
_adj_fdivr_m32( unsigned int arg
)
1947 TRACE("(): stub\n");
1950 /***********************************************************************
1951 * _adj_fdivr_m32i (MSVCRT.@)
1954 * I _think_ this function is intended to work around the Pentium
1957 void __stdcall
_adj_fdivr_m32i( int arg
)
1959 TRACE("(): stub\n");
1962 /***********************************************************************
1963 * _adj_fdivr_m64 (MSVCRT.@)
1966 * I _think_ this function is intended to work around the Pentium
1969 void __stdcall
_adj_fdivr_m64( unsigned __int64 arg
)
1971 TRACE("(): stub\n");
1974 /***********************************************************************
1975 * _adj_fpatan (MSVCRT.@)
1977 * This function is likely to have the wrong number of arguments.
1980 * I _think_ this function is intended to work around the Pentium
1983 void _adj_fpatan(void)
1985 TRACE("(): stub\n");
1988 /***********************************************************************
1989 * _adj_fprem (MSVCRT.@)
1991 * This function is likely to have the wrong number of arguments.
1994 * I _think_ this function is intended to work around the Pentium
1997 void _adj_fprem(void)
1999 TRACE("(): stub\n");
2002 /***********************************************************************
2003 * _adj_fprem1 (MSVCRT.@)
2005 * This function is likely to have the wrong number of arguments.
2008 * I _think_ this function is intended to work around the Pentium
2011 void _adj_fprem1(void)
2013 TRACE("(): stub\n");
2016 /***********************************************************************
2017 * _adj_fptan (MSVCRT.@)
2019 * This function is likely to have the wrong number of arguments.
2022 * I _think_ this function is intended to work around the Pentium
2025 void _adj_fptan(void)
2027 TRACE("(): stub\n");
2030 /***********************************************************************
2031 * _safe_fdiv (MSVCRT.@)
2033 * This function is likely to have the wrong number of arguments.
2036 * I _think_ this function is intended to work around the Pentium
2039 void _safe_fdiv(void)
2041 TRACE("(): stub\n");
2044 /***********************************************************************
2045 * _safe_fdivr (MSVCRT.@)
2047 * This function is likely to have the wrong number of arguments.
2050 * I _think_ this function is intended to work around the Pentium
2053 void _safe_fdivr(void)
2055 TRACE("(): stub\n");
2058 /***********************************************************************
2059 * _safe_fprem (MSVCRT.@)
2061 * This function is likely to have the wrong number of arguments.
2064 * I _think_ this function is intended to work around the Pentium
2067 void _safe_fprem(void)
2069 TRACE("(): stub\n");
2072 /***********************************************************************
2073 * _safe_fprem1 (MSVCRT.@)
2076 * This function is likely to have the wrong number of arguments.
2079 * I _think_ this function is intended to work around the Pentium
2082 void _safe_fprem1(void)
2084 TRACE("(): stub\n");
2087 /***********************************************************************
2088 * __libm_sse2_acos (MSVCRT.@)
2090 void __cdecl
MSVCRT___libm_sse2_acos(void)
2093 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2095 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2098 /***********************************************************************
2099 * __libm_sse2_acosf (MSVCRT.@)
2101 void __cdecl
MSVCRT___libm_sse2_acosf(void)
2104 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2106 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2109 /***********************************************************************
2110 * __libm_sse2_asin (MSVCRT.@)
2112 void __cdecl
MSVCRT___libm_sse2_asin(void)
2115 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2117 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2120 /***********************************************************************
2121 * __libm_sse2_asinf (MSVCRT.@)
2123 void __cdecl
MSVCRT___libm_sse2_asinf(void)
2126 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2128 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2131 /***********************************************************************
2132 * __libm_sse2_atan (MSVCRT.@)
2134 void __cdecl
MSVCRT___libm_sse2_atan(void)
2137 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2139 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2142 /***********************************************************************
2143 * __libm_sse2_atan2 (MSVCRT.@)
2145 void __cdecl
MSVCRT___libm_sse2_atan2(void)
2148 __asm__
__volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1
), "=m" (d2
) );
2149 d1
= atan2( d1
, d2
);
2150 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d1
) );
2153 /***********************************************************************
2154 * __libm_sse2_atanf (MSVCRT.@)
2156 void __cdecl
MSVCRT___libm_sse2_atanf(void)
2159 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2161 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2164 /***********************************************************************
2165 * __libm_sse2_cos (MSVCRT.@)
2167 void __cdecl
MSVCRT___libm_sse2_cos(void)
2170 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2172 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2175 /***********************************************************************
2176 * __libm_sse2_cosf (MSVCRT.@)
2178 void __cdecl
MSVCRT___libm_sse2_cosf(void)
2181 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2183 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2186 /***********************************************************************
2187 * __libm_sse2_exp (MSVCRT.@)
2189 void __cdecl
MSVCRT___libm_sse2_exp(void)
2192 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2194 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2197 /***********************************************************************
2198 * __libm_sse2_expf (MSVCRT.@)
2200 void __cdecl
MSVCRT___libm_sse2_expf(void)
2203 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2205 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2208 /***********************************************************************
2209 * __libm_sse2_log (MSVCRT.@)
2211 void __cdecl
MSVCRT___libm_sse2_log(void)
2214 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2216 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2219 /***********************************************************************
2220 * __libm_sse2_log10 (MSVCRT.@)
2222 void __cdecl
MSVCRT___libm_sse2_log10(void)
2225 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2227 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2230 /***********************************************************************
2231 * __libm_sse2_log10f (MSVCRT.@)
2233 void __cdecl
MSVCRT___libm_sse2_log10f(void)
2236 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2238 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2241 /***********************************************************************
2242 * __libm_sse2_logf (MSVCRT.@)
2244 void __cdecl
MSVCRT___libm_sse2_logf(void)
2247 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2249 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2252 /***********************************************************************
2253 * __libm_sse2_pow (MSVCRT.@)
2255 void __cdecl
MSVCRT___libm_sse2_pow(void)
2258 __asm__
__volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1
), "=m" (d2
) );
2260 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d1
) );
2263 /***********************************************************************
2264 * __libm_sse2_powf (MSVCRT.@)
2266 void __cdecl
MSVCRT___libm_sse2_powf(void)
2269 __asm__
__volatile__( "movd %%xmm0,%0; movd %%xmm1,%1" : "=g" (f1
), "=g" (f2
) );
2270 f1
= powf( f1
, f2
);
2271 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f1
) );
2274 /***********************************************************************
2275 * __libm_sse2_sin (MSVCRT.@)
2277 void __cdecl
MSVCRT___libm_sse2_sin(void)
2280 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2282 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2285 /***********************************************************************
2286 * __libm_sse2_sinf (MSVCRT.@)
2288 void __cdecl
MSVCRT___libm_sse2_sinf(void)
2291 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2293 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2296 /***********************************************************************
2297 * __libm_sse2_tan (MSVCRT.@)
2299 void __cdecl
MSVCRT___libm_sse2_tan(void)
2302 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2304 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2307 /***********************************************************************
2308 * __libm_sse2_tanf (MSVCRT.@)
2310 void __cdecl
MSVCRT___libm_sse2_tanf(void)
2313 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2315 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2318 /***********************************************************************
2319 * __libm_sse2_sqrt_precise (MSVCR110.@)
2321 void __cdecl
MSVCRT___libm_sse2_sqrt_precise(void)
2324 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2326 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2329 #endif /* __i386__ */
2331 /*********************************************************************
2334 double CDECL
MSVCR120_cbrt(double x
)
2339 return x
< 0 ? -pow(-x
, 1.0 / 3.0) : pow(x
, 1.0 / 3.0);
2343 /*********************************************************************
2344 * cbrtf (MSVCR120.@)
2346 float CDECL
MSVCR120_cbrtf(float x
)
2351 return MSVCR120_cbrt(x
);
2355 /*********************************************************************
2356 * cbrtl (MSVCR120.@)
2358 LDOUBLE CDECL
MSVCR120_cbrtl(LDOUBLE x
)
2360 return MSVCR120_cbrt(x
);
2363 /*********************************************************************
2366 double CDECL
MSVCR120_exp2(double x
)
2375 /*********************************************************************
2376 * exp2f (MSVCR120.@)
2378 float CDECL
MSVCR120_exp2f(float x
)
2383 return MSVCR120_exp2(x
);
2387 /*********************************************************************
2388 * exp2l (MSVCR120.@)
2390 LDOUBLE CDECL
MSVCR120_exp2l(LDOUBLE x
)
2392 return MSVCR120_exp2(x
);
2395 /*********************************************************************
2398 double CDECL
MSVCR120_log2(double x
)
2403 return log(x
) / log(2);
2407 /*********************************************************************
2408 * log2f (MSVCR120.@)
2410 float CDECL
MSVCR120_log2f(float x
)
2415 return MSVCR120_log2(x
);
2419 /*********************************************************************
2420 * log2l (MSVCR120.@)
2422 LDOUBLE CDECL
MSVCR120_log2l(LDOUBLE x
)
2424 return MSVCR120_log2(x
);
2427 /*********************************************************************
2430 double CDECL
MSVCR120_rint(double x
)
2435 return x
>= 0 ? floor(x
+ 0.5) : ceil(x
- 0.5);
2439 /*********************************************************************
2440 * rintf (MSVCR120.@)
2442 float CDECL
MSVCR120_rintf(float x
)
2447 return MSVCR120_rint(x
);
2451 /*********************************************************************
2452 * rintl (MSVCR120.@)
2454 LDOUBLE CDECL
MSVCR120_rintl(LDOUBLE x
)
2456 return MSVCR120_rint(x
);
2459 /*********************************************************************
2460 * lrint (MSVCR120.@)
2462 MSVCRT_long CDECL
MSVCR120_lrint(double x
)
2467 return MSVCR120_rint(x
);
2471 /*********************************************************************
2472 * lrintf (MSVCR120.@)
2474 MSVCRT_long CDECL
MSVCR120_lrintf(float x
)
2479 return MSVCR120_lrint(x
);
2483 /*********************************************************************
2484 * lrintl (MSVCR120.@)
2486 MSVCRT_long CDECL
MSVCR120_lrintl(LDOUBLE x
)
2488 return MSVCR120_lrint(x
);
2491 /*********************************************************************
2492 * llrint (MSVCR120.@)
2494 MSVCRT_longlong CDECL
MSVCR120_llrint(double x
)
2499 return MSVCR120_rint(x
);
2503 /*********************************************************************
2504 * llrintf (MSVCR120.@)
2506 MSVCRT_longlong CDECL
MSVCR120_llrintf(float x
)
2511 return MSVCR120_llrint(x
);
2515 /*********************************************************************
2516 * rintl (MSVCR120.@)
2518 MSVCRT_longlong CDECL
MSVCR120_llrintl(LDOUBLE x
)
2520 return MSVCR120_llrint(x
);
2523 /*********************************************************************
2524 * round (MSVCR120.@)
2526 double CDECL
MSVCR120_round(double x
)
2531 return MSVCR120_rint(x
);
2535 /*********************************************************************
2536 * roundf (MSVCR120.@)
2538 float CDECL
MSVCR120_roundf(float x
)
2543 return MSVCR120_round(x
);
2547 /*********************************************************************
2548 * roundl (MSVCR120.@)
2550 LDOUBLE CDECL
MSVCR120_roundl(LDOUBLE x
)
2552 return MSVCR120_round(x
);
2555 /*********************************************************************
2556 * lround (MSVCR120.@)
2558 MSVCRT_long CDECL
MSVCR120_lround(double x
)
2563 return MSVCR120_round(x
);
2567 /*********************************************************************
2568 * lroundf (MSVCR120.@)
2570 MSVCRT_long CDECL
MSVCR120_lroundf(float x
)
2575 return MSVCR120_lround(x
);
2579 /*********************************************************************
2580 * lroundl (MSVCR120.@)
2582 MSVCRT_long CDECL
MSVCR120_lroundl(LDOUBLE x
)
2584 return MSVCR120_lround(x
);
2587 /*********************************************************************
2588 * llround (MSVCR120.@)
2590 MSVCRT_longlong CDECL
MSVCR120_llround(double x
)
2595 return MSVCR120_round(x
);
2599 /*********************************************************************
2600 * llroundf (MSVCR120.@)
2602 MSVCRT_longlong CDECL
MSVCR120_llroundf(float x
)
2604 #ifdef HAVE_LLROUNDF
2607 return MSVCR120_llround(x
);
2611 /*********************************************************************
2612 * roundl (MSVCR120.@)
2614 MSVCRT_longlong CDECL
MSVCR120_llroundl(LDOUBLE x
)
2616 return MSVCR120_llround(x
);
2619 /*********************************************************************
2620 * trunc (MSVCR120.@)
2622 double CDECL
MSVCR120_trunc(double x
)
2627 return (x
> 0) ? floor(x
) : ceil(x
);
2631 /*********************************************************************
2632 * truncf (MSVCR120.@)
2634 float CDECL
MSVCR120_truncf(float x
)
2639 return MSVCR120_trunc(x
);
2643 /*********************************************************************
2644 * truncl (MSVCR120.@)
2646 LDOUBLE CDECL
MSVCR120_truncl(LDOUBLE x
)
2648 return MSVCR120_trunc(x
);
2651 /*********************************************************************
2652 * _dclass (MSVCR120.@)
2654 short CDECL
MSVCR120__dclass(double x
)
2656 switch (MSVCRT__fpclass(x
)) {
2657 case MSVCRT__FPCLASS_QNAN
:
2658 case MSVCRT__FPCLASS_SNAN
:
2659 return MSVCRT_FP_NAN
;
2660 case MSVCRT__FPCLASS_NINF
:
2661 case MSVCRT__FPCLASS_PINF
:
2662 return MSVCRT_FP_INFINITE
;
2663 case MSVCRT__FPCLASS_ND
:
2664 case MSVCRT__FPCLASS_PD
:
2665 return MSVCRT_FP_SUBNORMAL
;
2666 case MSVCRT__FPCLASS_NN
:
2667 case MSVCRT__FPCLASS_PN
:
2669 return MSVCRT_FP_NORMAL
;
2670 case MSVCRT__FPCLASS_NZ
:
2671 case MSVCRT__FPCLASS_PZ
:
2672 return MSVCRT_FP_ZERO
;
2676 /*********************************************************************
2677 * _fdclass (MSVCR120.@)
2679 short CDECL
MSVCR120__fdclass(float x
)
2681 return MSVCR120__dclass(x
);
2684 /*********************************************************************
2685 * _ldclass (MSVCR120.@)
2687 short CDECL
MSVCR120__ldclass(LDOUBLE x
)
2689 return MSVCR120__dclass(x
);
2692 /*********************************************************************
2693 * _dtest (MSVCR120.@)
2695 short CDECL
MSVCR120__dtest(double *x
)
2697 return MSVCR120__dclass(*x
);
2700 /*********************************************************************
2701 * _fdtest (MSVCR120.@)
2703 short CDECL
MSVCR120__fdtest(float *x
)
2705 return MSVCR120__dclass(*x
);
2708 /*********************************************************************
2709 * _ldtest (MSVCR120.@)
2711 short CDECL
MSVCR120__ldtest(LDOUBLE
*x
)
2713 return MSVCR120__dclass(*x
);
2716 /*********************************************************************
2719 float CDECL
MSVCR120_erff(float x
)
2724 FIXME( "not implemented\n" );
2729 /*********************************************************************
2732 double CDECL
MSVCR120_erf(double x
)
2737 FIXME( "not implemented\n" );
2742 /*********************************************************************
2745 LDOUBLE CDECL
MSVCR120_erfl(LDOUBLE x
)
2747 return MSVCR120_erf(x
);
2750 /*********************************************************************
2751 * fmaxf (MSVCR120.@)
2753 float CDECL
MSVCR120_fmaxf(float x
, float y
)
2760 return signbit(x
) ? y
: x
;
2764 /*********************************************************************
2767 double CDECL
MSVCR120_fmax(double x
, double y
)
2774 return signbit(x
) ? y
: x
;
2778 /*********************************************************************
2779 * _fdsign (MSVCR120.@)
2781 int CDECL
MSVCR120__fdsign(float x
)
2783 return signbit(x
) ? 0x8000 : 0;
2786 /*********************************************************************
2787 * _dsign (MSVCR120.@)
2789 int CDECL
MSVCR120__dsign(double x
)
2791 return signbit(x
) ? 0x8000 : 0;
2795 /*********************************************************************
2796 * _dpcomp (MSVCR120.@)
2798 int CDECL
MSVCR120__dpcomp(double x
, double y
)
2800 if(isnan(x
) || isnan(y
))
2803 if(x
== y
) return 2;
2804 return x
< y
? 1 : 4;
2807 /*********************************************************************
2808 * _fdpcomp (MSVCR120.@)
2810 int CDECL
MSVCR120__fdpcomp(float x
, float y
)
2812 return MSVCR120__dpcomp(x
, y
);
2815 /*********************************************************************
2816 * fminf (MSVCR120.@)
2818 float CDECL
MSVCR120_fminf(float x
, float y
)
2825 return signbit(x
) ? x
: y
;
2829 /*********************************************************************
2832 double CDECL
MSVCR120_fmin(double x
, double y
)
2839 return signbit(x
) ? x
: y
;
2843 /*********************************************************************
2844 * asinh (MSVCR120.@)
2846 double CDECL
MSVCR120_asinh(double x
)
2851 FIXME( "not implemented\n" );
2856 /*********************************************************************
2857 * asinhf (MSVCR120.@)
2859 float CDECL
MSVCR120_asinhf(float x
)
2864 FIXME( "not implemented\n" );
2869 /*********************************************************************
2870 * asinhl (MSVCR120.@)
2872 LDOUBLE CDECL
MSVCR120_asinhl(LDOUBLE x
)
2874 return MSVCR120_asinh(x
);
2877 /*********************************************************************
2879 * scalbn (MSVCR120.@)
2880 * scalbln (MSVCR120.@)
2882 double CDECL
MSVCRT__scalb(double num
, MSVCRT_long power
)
2884 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
2885 return ldexp(num
, power
);
2888 /*********************************************************************
2889 * _scalbf (MSVCRT.@)
2890 * scalbnf (MSVCR120.@)
2891 * scalblnf (MSVCR120.@)
2893 float CDECL
MSVCRT__scalbf(float num
, MSVCRT_long power
)
2895 if (!finitef(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
2896 return ldexpf(num
, power
);
2899 /*********************************************************************
2900 * scalbnl (MSVCR120.@)
2901 * scalblnl (MSVCR120.@)
2903 LDOUBLE CDECL
MSVCR120_scalbnl(LDOUBLE num
, MSVCRT_long power
)
2905 return MSVCRT__scalb(num
, power
);
2908 /*********************************************************************
2909 * remainder (MSVCR120.@)
2911 double CDECL
MSVCR120_remainder(double x
, double y
)
2913 #ifdef HAVE_REMAINDER
2914 /* this matches 64-bit Windows. 32-bit Windows is slightly different */
2915 if(!finite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
2916 if(isnan(y
) || y
==0.0) *MSVCRT__errno() = MSVCRT_EDOM
;
2917 return remainder(x
, y
);
2919 FIXME( "not implemented\n" );
2924 /*********************************************************************
2925 * remainderf (MSVCR120.@)
2927 float CDECL
MSVCR120_remainderf(float x
, float y
)
2929 #ifdef HAVE_REMAINDERF
2930 /* this matches 64-bit Windows. 32-bit Windows is slightly different */
2931 if(!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
2932 if(isnanf(y
) || y
==0.0f
) *MSVCRT__errno() = MSVCRT_EDOM
;
2933 return remainderf(x
, y
);
2935 FIXME( "not implemented\n" );
2940 /*********************************************************************
2941 * remainderl (MSVCR120.@)
2943 LDOUBLE CDECL
MSVCR120_remainderl(LDOUBLE x
, LDOUBLE y
)
2945 return MSVCR120_remainder(x
, y
);
2948 /*********************************************************************
2949 * lgamma (MSVCR120.@)
2951 double CDECL
MSVCR120_lgamma(double x
)
2956 FIXME( "not implemented\n" );
2961 /*********************************************************************
2962 * lgammaf (MSVCR120.@)
2964 float CDECL
MSVCR120_lgammaf(float x
)
2969 FIXME( "not implemented\n" );
2974 /*********************************************************************
2975 * lgammal (MSVCR120.@)
2977 LDOUBLE CDECL
MSVCR120_lgammal(LDOUBLE x
)
2979 return MSVCR120_lgamma(x
);
2982 /*********************************************************************
2985 double CDECL
MSVCR120_nan(const char *tagp
)
2987 /* Windows ignores input (MSDN) */
2991 /*********************************************************************
2994 float CDECL
MSVCR120_nanf(const char *tagp
)
2999 /*********************************************************************
3000 * _except1 (MSVCR120.@)
3002 * - find meaning of ignored cw and operation bits
3005 double CDECL
_except1(DWORD fpe
, _FP_OPERATION_CODE op
, double arg
, double res
, DWORD cw
, void *unk
)
3007 ULONG_PTR exception_arg
;
3008 DWORD exception
= 0;
3013 TRACE("(%x %x %lf %lf %x %p)\n", fpe
, op
, arg
, res
, cw
, unk
);
3016 cw
= ((cw
>> 7) & 0x3f) | ((cw
>> 3) & 0xc00);
3018 operation
= op
<< 5;
3019 exception_arg
= (ULONG_PTR
)&operation
;
3021 MSVCRT_fegetenv(&env
);
3023 if (fpe
& 0x1) { /* overflow */
3024 if ((fpe
== 0x1 && (cw
& 0x8)) || (fpe
==0x11 && (cw
& 0x28))) {
3025 /* 32-bit version also sets SW_INEXACT here */
3026 env
.status
|= MSVCRT__SW_OVERFLOW
;
3027 if (fpe
& 0x10) env
.status
|= MSVCRT__SW_INEXACT
;
3028 res
= signbit(res
) ? -INFINITY
: INFINITY
;
3030 exception
= EXCEPTION_FLT_OVERFLOW
;
3032 } else if (fpe
& 0x2) { /* underflow */
3033 if ((fpe
== 0x2 && (cw
& 0x10)) || (fpe
==0x12 && (cw
& 0x30))) {
3034 env
.status
|= MSVCRT__SW_UNDERFLOW
;
3035 if (fpe
& 0x10) env
.status
|= MSVCRT__SW_INEXACT
;
3036 res
= signbit(res
) ? -0.0 : 0.0;
3038 exception
= EXCEPTION_FLT_UNDERFLOW
;
3040 } else if (fpe
& 0x4) { /* zerodivide */
3041 if ((fpe
== 0x4 && (cw
& 0x4)) || (fpe
==0x14 && (cw
& 0x24))) {
3042 env
.status
|= MSVCRT__SW_ZERODIVIDE
;
3043 if (fpe
& 0x10) env
.status
|= MSVCRT__SW_INEXACT
;
3045 exception
= EXCEPTION_FLT_DIVIDE_BY_ZERO
;
3047 } else if (fpe
& 0x8) { /* invalid */
3048 if (fpe
== 0x8 && (cw
& 0x1)) {
3049 env
.status
|= MSVCRT__SW_INVALID
;
3051 exception
= EXCEPTION_FLT_INVALID_OPERATION
;
3053 } else if (fpe
& 0x10) { /* inexact */
3054 if (fpe
== 0x10 && (cw
& 0x20)) {
3055 env
.status
|= MSVCRT__SW_INEXACT
;
3057 exception
= EXCEPTION_FLT_INEXACT_RESULT
;
3063 MSVCRT_fesetenv(&env
);
3065 RaiseException(exception
, 0, 1, &exception_arg
);
3067 if (cw
& 0x1) fpword
|= MSVCRT__EM_INVALID
;
3068 if (cw
& 0x2) fpword
|= MSVCRT__EM_DENORMAL
;
3069 if (cw
& 0x4) fpword
|= MSVCRT__EM_ZERODIVIDE
;
3070 if (cw
& 0x8) fpword
|= MSVCRT__EM_OVERFLOW
;
3071 if (cw
& 0x10) fpword
|= MSVCRT__EM_UNDERFLOW
;
3072 if (cw
& 0x20) fpword
|= MSVCRT__EM_INEXACT
;
3075 case 0xc00: fpword
|= MSVCRT__RC_UP
|MSVCRT__RC_DOWN
; break;
3076 case 0x800: fpword
|= MSVCRT__RC_UP
; break;
3077 case 0x400: fpword
|= MSVCRT__RC_DOWN
; break;
3081 case 0x0: fpword
|= MSVCRT__PC_24
; break;
3082 case 0x200: fpword
|= MSVCRT__PC_53
; break;
3083 case 0x300: fpword
|= MSVCRT__PC_64
; break;
3085 if (cw
& 0x1000) fpword
|= MSVCRT__IC_AFFINE
;
3086 _control87(fpword
, 0xffffffff);