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 * For functions copied from musl libc (http://musl.libc.org/):
22 * ====================================================
23 * Copyright 2005-2020 Rich Felker, et al.
25 * Permission is hereby granted, free of charge, to any person obtaining
26 * a copy of this software and associated documentation files (the
27 * "Software"), to deal in the Software without restriction, including
28 * without limitation the rights to use, copy, modify, merge, publish,
29 * distribute, sublicense, and/or sell copies of the Software, and to
30 * permit persons to whom the Software is furnished to do so, subject to
31 * the following conditions:
33 * The above copyright notice and this permission notice shall be
34 * included in all copies or substantial portions of the Software.
35 * ====================================================
39 #include "wine/port.h"
42 #define __USE_ISOC9X 1
43 #define __USE_ISOC99 1
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
56 #define _DOMAIN 1 /* domain error in argument */
57 #define _SING 2 /* singularity */
58 #define _OVERFLOW 3 /* range overflow */
59 #define _UNDERFLOW 4 /* range underflow */
61 typedef int (CDECL
*MSVCRT_matherr_func
)(struct MSVCRT__exception
*);
62 typedef double LDOUBLE
; /* long double is just a double */
64 static MSVCRT_matherr_func MSVCRT_default_matherr_func
= NULL
;
66 static BOOL sse2_supported
;
67 static BOOL sse2_enabled
;
69 void msvcrt_init_math(void)
71 sse2_supported
= sse2_enabled
= IsProcessorFeaturePresent( PF_XMMI64_INSTRUCTIONS_AVAILABLE
);
74 /* Copied from musl: src/internal/libm.h */
75 static inline float fp_barrierf(float x
)
81 /*********************************************************************
84 int CDECL
MSVCRT__matherr(struct MSVCRT__exception
*e
)
90 static double math_error(int type
, const char *name
, double arg1
, double arg2
, double retval
)
92 struct MSVCRT__exception exception
= {type
, (char *)name
, arg1
, arg2
, retval
};
94 TRACE("(%d, %s, %g, %g, %g)\n", type
, debugstr_a(name
), arg1
, arg2
, retval
);
96 if (MSVCRT_default_matherr_func
&& MSVCRT_default_matherr_func(&exception
))
97 return exception
.retval
;
102 *MSVCRT__errno() = MSVCRT_EDOM
;
106 *MSVCRT__errno() = MSVCRT_ERANGE
;
109 /* don't set errno */
112 ERR("Unhandled math error!\n");
115 return exception
.retval
;
118 /*********************************************************************
119 * __setusermatherr (MSVCRT.@)
121 void CDECL
MSVCRT___setusermatherr(MSVCRT_matherr_func func
)
123 MSVCRT_default_matherr_func
= func
;
124 TRACE("new matherr handler %p\n", func
);
127 /*********************************************************************
128 * _set_SSE2_enable (MSVCRT.@)
130 int CDECL
MSVCRT__set_SSE2_enable(int flag
)
132 sse2_enabled
= flag
&& sse2_supported
;
138 /*********************************************************************
139 * _get_FMA3_enable (UCRTBASE.@)
141 int CDECL
MSVCRT__get_FMA3_enable(void)
149 /*********************************************************************
150 * _set_FMA3_enable (MSVCR120.@)
152 int CDECL
MSVCRT__set_FMA3_enable(int flag
)
154 FIXME("(%x) stub\n", flag
);
160 #if !defined(__i386__) || _MSVCR_VER>=120
162 /*********************************************************************
163 * _chgsignf (MSVCRT.@)
165 float CDECL
MSVCRT__chgsignf( float num
)
167 union { float f
; UINT32 i
; } u
= { num
};
172 /*********************************************************************
173 * _copysignf (MSVCRT.@)
175 * Copied from musl: src/math/copysignf.c
177 float CDECL
MSVCRT__copysignf( float x
, float y
)
179 union { float f
; UINT32 i
; } ux
= { x
}, uy
= { y
};
181 ux
.i
|= uy
.i
& 0x80000000;
185 /*********************************************************************
186 * _nextafterf (MSVCRT.@)
188 float CDECL
MSVCRT__nextafterf( float num
, float next
)
190 if (!isfinite(num
) || !isfinite(next
)) *MSVCRT__errno() = MSVCRT_EDOM
;
191 return nextafterf( num
, next
);
194 /*********************************************************************
197 float CDECL
MSVCRT__logbf( float num
)
199 float ret
= logbf(num
);
200 if (isnan(num
)) return math_error(_DOMAIN
, "_logbf", num
, 0, ret
);
201 if (!num
) return math_error(_SING
, "_logbf", num
, 0, ret
);
209 /*********************************************************************
210 * _fpclassf (MSVCRT.@)
212 int CDECL
MSVCRT__fpclassf( float num
)
214 union { float f
; UINT32 i
; } u
= { num
};
215 int e
= u
.i
>> 23 & 0xff;
221 if (u
.i
<< 1) return s
? MSVCRT__FPCLASS_ND
: MSVCRT__FPCLASS_PD
;
222 return s
? MSVCRT__FPCLASS_NZ
: MSVCRT__FPCLASS_PZ
;
224 if (u
.i
<< 9) return ((u
.i
>> 22) & 1) ? MSVCRT__FPCLASS_QNAN
: MSVCRT__FPCLASS_SNAN
;
225 return s
? MSVCRT__FPCLASS_NINF
: MSVCRT__FPCLASS_PINF
;
227 return s
? MSVCRT__FPCLASS_NN
: MSVCRT__FPCLASS_PN
;
231 /*********************************************************************
232 * _finitef (MSVCRT.@)
234 int CDECL
MSVCRT__finitef( float num
)
236 union { float f
; UINT32 i
; } u
= { num
};
237 return (u
.i
& 0x7fffffff) < 0x7f800000;
240 /*********************************************************************
243 int CDECL
MSVCRT__isnanf( float num
)
245 union { float f
; UINT32 i
; } u
= { num
};
246 return (u
.i
& 0x7fffffff) > 0x7f800000;
249 /*********************************************************************
250 * MSVCRT_acosf (MSVCRT.@)
252 * Copied from musl: src/math/acosf.c
254 static float acosf_R(float z
)
256 static const float pS0
= 1.6666586697e-01,
257 pS1
= -4.2743422091e-02,
258 pS2
= -8.6563630030e-03,
259 qS1
= -7.0662963390e-01;
262 p
= z
* (pS0
+ z
* (pS1
+ z
* pS2
));
267 float CDECL
MSVCRT_acosf( float x
)
269 static const float pio2_hi
= 1.5707962513e+00,
270 pio2_lo
= 7.5497894159e-08;
272 float z
, w
, s
, c
, df
;
275 hx
= *(unsigned int*)&x
;
276 ix
= hx
& 0x7fffffff;
277 /* |x| >= 1 or nan */
278 if (ix
>= 0x3f800000) {
279 if (ix
== 0x3f800000) {
281 return 2 * pio2_lo
+ 2 * pio2_hi
+ 7.5231638453e-37;
284 if (isnan(x
)) return x
;
285 return math_error(_DOMAIN
, "acosf", x
, 0, 0 / (x
- x
));
288 if (ix
< 0x3f000000) {
289 if (ix
<= 0x32800000) /* |x| < 2**-26 */
290 return pio2_lo
+ pio2_hi
+ 7.5231638453e-37;
291 return pio2_hi
- (x
- (pio2_lo
- x
* acosf_R(x
* x
)));
297 w
= acosf_R(z
) * s
- pio2_lo
;
298 return 2 * (pio2_hi
- (s
+ w
));
303 hx
= *(unsigned int*)&s
& 0xfffff000;
305 c
= (z
- df
* df
) / (s
+ df
);
306 w
= acosf_R(z
) * s
+ c
;
310 /*********************************************************************
311 * MSVCRT_asinf (MSVCRT.@)
313 * Copied from musl: src/math/asinf.c
315 static float asinf_R(float z
)
317 /* coefficients for R(x^2) */
318 static const float pS0
= 1.6666586697e-01,
319 pS1
= -4.2743422091e-02,
320 pS2
= -8.6563630030e-03,
321 qS1
= -7.0662963390e-01;
324 p
= z
* (pS0
+ z
* (pS1
+ z
* pS2
));
329 float CDECL
MSVCRT_asinf( float x
)
331 static const double pio2
= 1.570796326794896558e+00;
337 hx
= *(unsigned int*)&x
;
338 ix
= hx
& 0x7fffffff;
339 if (ix
>= 0x3f800000) { /* |x| >= 1 */
340 if (ix
== 0x3f800000) /* |x| == 1 */
341 return x
* pio2
+ 7.5231638453e-37; /* asin(+-1) = +-pi/2 with inexact */
342 if (isnan(x
)) return x
;
343 return math_error(_DOMAIN
, "asinf", x
, 0, 0 / (x
- x
));
345 if (ix
< 0x3f000000) { /* |x| < 0.5 */
346 /* if 0x1p-126 <= |x| < 0x1p-12, avoid raising underflow */
347 if (ix
< 0x39800000 && ix
>= 0x00800000)
349 return x
+ x
* asinf_R(x
* x
);
352 z
= (1 - fabsf(x
)) * 0.5f
;
354 x
= pio2
- 2 * (s
+ s
* asinf_R(z
));
360 /*********************************************************************
361 * MSVCRT_atanf (MSVCRT.@)
363 * Copied from musl: src/math/atanf.c
365 float CDECL
MSVCRT_atanf( float x
)
367 static const float atanhi
[] = {
373 static const float atanlo
[] = {
379 static const float aT
[] = {
388 unsigned int ix
, sign
;
392 if (isnan(x
)) return math_error(_DOMAIN
, "atanf", x
, 0, x
);
395 ix
= *(unsigned int*)&x
;
398 if (ix
>= 0x4c800000) { /* if |x| >= 2**26 */
401 z
= atanhi
[3] + 7.5231638453e-37;
402 return sign
? -z
: z
;
404 if (ix
< 0x3ee00000) { /* |x| < 0.4375 */
405 if (ix
< 0x39800000) { /* |x| < 2**-12 */
407 /* raise underflow for subnormal x */
414 if (ix
< 0x3f980000) { /* |x| < 1.1875 */
415 if (ix
< 0x3f300000) { /* 7/16 <= |x| < 11/16 */
417 x
= (2.0f
* x
- 1.0f
) / (2.0f
+ x
);
418 } else { /* 11/16 <= |x| < 19/16 */
420 x
= (x
- 1.0f
) / (x
+ 1.0f
);
423 if (ix
< 0x401c0000) { /* |x| < 2.4375 */
425 x
= (x
- 1.5f
) / (1.0f
+ 1.5f
* x
);
426 } else { /* 2.4375 <= |x| < 2**26 */
432 /* end of argument reduction */
435 /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */
436 s1
= z
* (aT
[0] + w
* (aT
[2] + w
* aT
[4]));
437 s2
= w
* (aT
[1] + w
* aT
[3]);
439 return x
- x
* (s1
+ s2
);
440 z
= atanhi
[id
] - ((x
* (s1
+ s2
) - atanlo
[id
]) - x
);
441 return sign
? -z
: z
;
444 /*********************************************************************
445 * MSVCRT_atan2f (MSVCRT.@)
447 * Copied from musl: src/math/atan2f.c
449 float CDECL
MSVCRT_atan2f( float y
, float x
)
451 static const float pi
= 3.1415927410e+00,
452 pi_lo
= -8.7422776573e-08;
455 unsigned int m
, ix
, iy
;
457 if (isnan(x
) || isnan(y
))
459 ix
= *(unsigned int*)&x
;
460 iy
= *(unsigned int*)&y
;
461 if (ix
== 0x3f800000) /* x=1.0 */
463 m
= ((iy
>> 31) & 1) | ((ix
>> 30) & 2); /* 2*sign(x)+sign(y) */
471 case 1: return y
; /* atan(+-0,+anything)=+-0 */
472 case 2: return pi
; /* atan(+0,-anything) = pi */
473 case 3: return -pi
; /* atan(-0,-anything) =-pi */
478 return m
& 1 ? -pi
/ 2 : pi
/ 2;
480 if (ix
== 0x7f800000) {
481 if (iy
== 0x7f800000) {
483 case 0: return pi
/ 4; /* atan(+INF,+INF) */
484 case 1: return -pi
/ 4; /* atan(-INF,+INF) */
485 case 2: return 3 * pi
/ 4; /*atan(+INF,-INF)*/
486 case 3: return -3 * pi
/ 4; /*atan(-INF,-INF)*/
490 case 0: return 0.0f
; /* atan(+...,+INF) */
491 case 1: return -0.0f
; /* atan(-...,+INF) */
492 case 2: return pi
; /* atan(+...,-INF) */
493 case 3: return -pi
; /* atan(-...,-INF) */
498 if (ix
+ (26 << 23) < iy
|| iy
== 0x7f800000)
499 return m
& 1 ? -pi
/ 2 : pi
/ 2;
501 /* z = atan(|y/x|) with correct underflow */
502 if ((m
& 2) && iy
+ (26 << 23) < ix
) /*|y/x| < 0x1p-26, x < 0 */
505 z
= atanf(fabsf(y
/ x
));
507 case 0: return z
; /* atan(+,+) */
508 case 1: return -z
; /* atan(-,+) */
509 case 2: return pi
- (z
- pi_lo
); /* atan(+,-) */
510 default: /* case 3 */
511 return (z
- pi_lo
) - pi
; /* atan(-,-) */
515 /*********************************************************************
516 * MSVCRT_cosf (MSVCRT.@)
518 float CDECL
MSVCRT_cosf( float x
)
521 if (!isfinite(x
)) return math_error(_DOMAIN
, "cosf", x
, 0, ret
);
525 /*********************************************************************
526 * MSVCRT_coshf (MSVCRT.@)
528 float CDECL
MSVCRT_coshf( float x
)
530 float ret
= coshf(x
);
531 if (isnan(x
)) return math_error(_DOMAIN
, "coshf", x
, 0, ret
);
535 /*********************************************************************
536 * MSVCRT_expf (MSVCRT.@)
538 float CDECL
MSVCRT_expf( float x
)
541 if (isnan(x
)) return math_error(_DOMAIN
, "expf", x
, 0, ret
);
542 if (isfinite(x
) && !ret
) return math_error(_UNDERFLOW
, "expf", x
, 0, ret
);
543 if (isfinite(x
) && !isfinite(ret
)) return math_error(_OVERFLOW
, "expf", x
, 0, ret
);
547 /*********************************************************************
548 * MSVCRT_fmodf (MSVCRT.@)
550 float CDECL
MSVCRT_fmodf( float x
, float y
)
552 float ret
= fmodf(x
, y
);
553 if (!isfinite(x
) || !isfinite(y
)) return math_error(_DOMAIN
, "fmodf", x
, 0, ret
);
557 /*********************************************************************
558 * MSVCRT_logf (MSVCRT.@)
560 float CDECL
MSVCRT_logf( float x
)
563 if (x
< 0.0) return math_error(_DOMAIN
, "logf", x
, 0, ret
);
564 if (x
== 0.0) return math_error(_SING
, "logf", x
, 0, ret
);
568 /*********************************************************************
569 * MSVCRT_log10f (MSVCRT.@)
571 float CDECL
MSVCRT_log10f( float x
)
573 float ret
= log10f(x
);
574 if (x
< 0.0) return math_error(_DOMAIN
, "log10f", x
, 0, ret
);
575 if (x
== 0.0) return math_error(_SING
, "log10f", x
, 0, ret
);
579 /*********************************************************************
580 * MSVCRT_powf (MSVCRT.@)
582 float CDECL
MSVCRT_powf( float x
, float y
)
585 if (x
< 0 && y
!= floorf(y
)) return math_error(_DOMAIN
, "powf", x
, y
, z
);
586 if (!x
&& isfinite(y
) && y
< 0) return math_error(_SING
, "powf", x
, y
, z
);
587 if (isfinite(x
) && isfinite(y
) && !isfinite(z
)) return math_error(_OVERFLOW
, "powf", x
, y
, z
);
588 if (x
&& isfinite(x
) && isfinite(y
) && !z
) return math_error(_UNDERFLOW
, "powf", x
, y
, z
);
592 /*********************************************************************
593 * MSVCRT_sinf (MSVCRT.@)
595 float CDECL
MSVCRT_sinf( float x
)
598 if (!isfinite(x
)) return math_error(_DOMAIN
, "sinf", x
, 0, ret
);
602 /*********************************************************************
603 * MSVCRT_sinhf (MSVCRT.@)
605 float CDECL
MSVCRT_sinhf( float x
)
607 float ret
= sinhf(x
);
608 if (isnan(x
)) return math_error(_DOMAIN
, "sinhf", x
, 0, ret
);
612 /*********************************************************************
613 * MSVCRT_sqrtf (MSVCRT.@)
615 * Copied from musl: src/math/sqrtf.c
617 float CDECL
MSVCRT_sqrtf( float x
)
619 static const float tiny
= 1.0e-30;
622 int sign
= 0x80000000;
628 /* take care of Inf and NaN */
629 if ((ix
& 0x7f800000) == 0x7f800000 && (ix
== 0x7f800000 || ix
& 0x7fffff))
632 /* take care of zero */
634 if ((ix
& ~sign
) == 0)
635 return x
; /* sqrt(+-0) = +-0 */
636 return math_error(_DOMAIN
, "sqrtf", x
, 0, (x
- x
) / (x
- x
)); /* sqrt(-ve) = sNaN */
640 if (m
== 0) { /* subnormal x */
641 for (i
= 0; (ix
& 0x00800000) == 0; i
++)
645 m
-= 127; /* unbias exponent */
646 ix
= (ix
& 0x007fffff) | 0x00800000;
647 if (m
& 1) /* odd m, double x to make it even */
649 m
>>= 1; /* m = [m/2] */
651 /* generate sqrt(x) bit by bit */
653 q
= s
= 0; /* q = sqrt(x) */
654 r
= 0x01000000; /* r = moving bit from right to left */
667 /* use floating add to find out rounding direction */
669 z
= 1.0f
- tiny
; /* raise inexact flag */
678 ix
= (q
>> 1) + 0x3f000000;
679 r
= ix
+ ((unsigned int)m
<< 23);
684 /*********************************************************************
685 * MSVCRT_tanf (MSVCRT.@)
687 float CDECL
MSVCRT_tanf( float x
)
690 if (!isfinite(x
)) return math_error(_DOMAIN
, "tanf", x
, 0, ret
);
694 /*********************************************************************
695 * MSVCRT_tanhf (MSVCRT.@)
697 float CDECL
MSVCRT_tanhf( float x
)
699 float ret
= tanhf(x
);
700 if (!isfinite(x
)) return math_error(_DOMAIN
, "tanhf", x
, 0, ret
);
704 /*********************************************************************
707 float CDECL
MSVCRT_ceilf( float x
)
712 /*********************************************************************
715 * Copied from musl: src/math/fabsf.c
717 float CDECL
MSVCRT_fabsf( float x
)
719 union { float f
; UINT32 i
; } u
= { x
};
724 /*********************************************************************
727 float CDECL
MSVCRT_floorf( float x
)
732 /*********************************************************************
735 float CDECL
MSVCRT_frexpf( float x
, int *exp
)
737 return frexpf( x
, exp
);
740 /*********************************************************************
743 float CDECL
MSVCRT_modff( float x
, float *iptr
)
745 return modff( x
, iptr
);
750 /*********************************************************************
751 * MSVCRT_acos (MSVCRT.@)
753 * Copied from musl: src/math/acos.c
755 static double acos_R(double z
)
757 static const double pS0
= 1.66666666666666657415e-01,
758 pS1
= -3.25565818622400915405e-01,
759 pS2
= 2.01212532134862925881e-01,
760 pS3
= -4.00555345006794114027e-02,
761 pS4
= 7.91534994289814532176e-04,
762 pS5
= 3.47933107596021167570e-05,
763 qS1
= -2.40339491173441421878e+00,
764 qS2
= 2.02094576023350569471e+00,
765 qS3
= -6.88283971605453293030e-01,
766 qS4
= 7.70381505559019352791e-02;
769 p
= z
* (pS0
+ z
* (pS1
+ z
* (pS2
+ z
* (pS3
+ z
* (pS4
+ z
* pS5
)))));
770 q
= 1.0 + z
* (qS1
+ z
* (qS2
+ z
* (qS3
+ z
* qS4
)));
774 double CDECL
MSVCRT_acos( double x
)
776 static const double pio2_hi
= 1.57079632679489655800e+00,
777 pio2_lo
= 6.12323399573676603587e-17;
779 double z
, w
, s
, c
, df
;
783 hx
= *(ULONGLONG
*)&x
>> 32;
784 ix
= hx
& 0x7fffffff;
785 /* |x| >= 1 or nan */
786 if (ix
>= 0x3ff00000) {
789 lx
= *(ULONGLONG
*)&x
;
790 if (((ix
- 0x3ff00000) | lx
) == 0) {
791 /* acos(1)=0, acos(-1)=pi */
793 return 2 * pio2_hi
+ 7.5231638452626401e-37;
796 if (isnan(x
)) return x
;
797 return math_error(_DOMAIN
, "acos", x
, 0, 0 / (x
- x
));
800 if (ix
< 0x3fe00000) {
801 if (ix
<= 0x3c600000) /* |x| < 2**-57 */
802 return pio2_hi
+ 7.5231638452626401e-37;
803 return pio2_hi
- (x
- (pio2_lo
- x
* acos_R(x
* x
)));
809 w
= acos_R(z
) * s
- pio2_lo
;
810 return 2 * (pio2_hi
- (s
+ w
));
816 llx
= (*(ULONGLONG
*)&df
>> 32) << 32;
818 c
= (z
- df
* df
) / (s
+ df
);
819 w
= acos_R(z
) * s
+ c
;
823 /*********************************************************************
824 * MSVCRT_asin (MSVCRT.@)
826 * Copied from musl: src/math/asin.c
828 static double asin_R(double z
)
830 /* coefficients for R(x^2) */
831 static const double pS0
= 1.66666666666666657415e-01,
832 pS1
= -3.25565818622400915405e-01,
833 pS2
= 2.01212532134862925881e-01,
834 pS3
= -4.00555345006794114027e-02,
835 pS4
= 7.91534994289814532176e-04,
836 pS5
= 3.47933107596021167570e-05,
837 qS1
= -2.40339491173441421878e+00,
838 qS2
= 2.02094576023350569471e+00,
839 qS3
= -6.88283971605453293030e-01,
840 qS4
= 7.70381505559019352791e-02;
843 p
= z
* (pS0
+ z
* (pS1
+ z
* (pS2
+ z
* (pS3
+ z
* (pS4
+ z
* pS5
)))));
844 q
= 1.0 + z
* (qS1
+ z
* (qS2
+ z
* (qS3
+ z
* qS4
)));
848 double CDECL
MSVCRT_asin( double x
)
850 static const double pio2_hi
= 1.57079632679489655800e+00,
851 pio2_lo
= 6.12323399573676603587e-17;
857 hx
= *(ULONGLONG
*)&x
>> 32;
858 ix
= hx
& 0x7fffffff;
859 /* |x| >= 1 or nan */
860 if (ix
>= 0x3ff00000) {
862 lx
= *(ULONGLONG
*)&x
;
863 if (((ix
- 0x3ff00000) | lx
) == 0)
864 /* asin(1) = +-pi/2 with inexact */
865 return x
* pio2_hi
+ 7.5231638452626401e-37;
866 if (isnan(x
)) return x
;
867 return math_error(_DOMAIN
, "asin", x
, 0, 0 / (x
- x
));
870 if (ix
< 0x3fe00000) {
871 /* if 0x1p-1022 <= |x| < 0x1p-26, avoid raising underflow */
872 if (ix
< 0x3e500000 && ix
>= 0x00100000)
874 return x
+ x
* asin_R(x
* x
);
877 z
= (1 - fabs(x
)) * 0.5;
880 if (ix
>= 0x3fef3333) { /* if |x| > 0.975 */
881 x
= pio2_hi
- (2 * (s
+ s
* r
) - pio2_lo
);
886 llx
= (*(ULONGLONG
*)&f
>> 32) << 32;
888 c
= (z
- f
* f
) / (s
+ f
);
889 x
= 0.5 * pio2_hi
- (2 * s
* r
- (pio2_lo
- 2 * c
) - (0.5 * pio2_hi
- 2 * f
));
896 /*********************************************************************
897 * MSVCRT_atan (MSVCRT.@)
899 * Copied from musl: src/math/atan.c
901 double CDECL
MSVCRT_atan( double x
)
903 static const double atanhi
[] = {
904 4.63647609000806093515e-01,
905 7.85398163397448278999e-01,
906 9.82793723247329054082e-01,
907 1.57079632679489655800e+00,
909 static const double atanlo
[] = {
910 2.26987774529616870924e-17,
911 3.06161699786838301793e-17,
912 1.39033110312309984516e-17,
913 6.12323399573676603587e-17,
915 static const double aT
[] = {
916 3.33333333333329318027e-01,
917 -1.99999999998764832476e-01,
918 1.42857142725034663711e-01,
919 -1.11111104054623557880e-01,
920 9.09088713343650656196e-02,
921 -7.69187620504482999495e-02,
922 6.66107313738753120669e-02,
923 -5.83357013379057348645e-02,
924 4.97687799461593236017e-02,
925 -3.65315727442169155270e-02,
926 1.62858201153657823623e-02,
930 unsigned int ix
, sign
;
934 if (isnan(x
)) return math_error(_DOMAIN
, "atan", x
, 0, x
);
937 ix
= *(ULONGLONG
*)&x
>> 32;
940 if (ix
>= 0x44100000) { /* if |x| >= 2^66 */
943 z
= atanhi
[3] + 7.5231638452626401e-37;
944 return sign
? -z
: z
;
946 if (ix
< 0x3fdc0000) { /* |x| < 0.4375 */
947 if (ix
< 0x3e400000) { /* |x| < 2^-27 */
949 /* raise underflow for subnormal x */
950 fp_barrierf((float)x
);
956 if (ix
< 0x3ff30000) { /* |x| < 1.1875 */
957 if (ix
< 0x3fe60000) { /* 7/16 <= |x| < 11/16 */
959 x
= (2.0 * x
- 1.0) / (2.0 + x
);
960 } else { /* 11/16 <= |x| < 19/16 */
962 x
= (x
- 1.0) / (x
+ 1.0);
965 if (ix
< 0x40038000) { /* |x| < 2.4375 */
967 x
= (x
- 1.5) / (1.0 + 1.5 * x
);
968 } else { /* 2.4375 <= |x| < 2^66 */
974 /* end of argument reduction */
977 /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */
978 s1
= z
* (aT
[0] + w
* (aT
[2] + w
* (aT
[4] + w
* (aT
[6] + w
* (aT
[8] + w
* aT
[10])))));
979 s2
= w
* (aT
[1] + w
* (aT
[3] + w
* (aT
[5] + w
* (aT
[7] + w
* aT
[9]))));
981 return x
- x
* (s1
+ s2
);
982 z
= atanhi
[id
] - (x
* (s1
+ s2
) - atanlo
[id
] - x
);
983 return sign
? -z
: z
;
986 /*********************************************************************
987 * MSVCRT_atan2 (MSVCRT.@)
989 * Copied from musl: src/math/atan2.c
991 double CDECL
MSVCRT_atan2( double y
, double x
)
993 static const double pi
= 3.1415926535897931160E+00,
994 pi_lo
= 1.2246467991473531772E-16;
997 unsigned int m
, lx
, ly
, ix
, iy
;
999 if (isnan(x
) || isnan(y
))
1001 ix
= *(ULONGLONG
*)&x
>> 32;
1002 lx
= *(ULONGLONG
*)&x
;
1003 iy
= *(ULONGLONG
*)&y
>> 32;
1004 ly
= *(ULONGLONG
*)&y
;
1005 if (((ix
- 0x3ff00000) | lx
) == 0) /* x = 1.0 */
1007 m
= ((iy
>> 31) & 1) | ((ix
>> 30) & 2); /* 2*sign(x)+sign(y) */
1008 ix
= ix
& 0x7fffffff;
1009 iy
= iy
& 0x7fffffff;
1012 if ((iy
| ly
) == 0) {
1015 case 1: return y
; /* atan(+-0,+anything)=+-0 */
1016 case 2: return pi
; /* atan(+0,-anything) = pi */
1017 case 3: return -pi
; /* atan(-0,-anything) =-pi */
1022 return m
& 1 ? -pi
/ 2 : pi
/ 2;
1024 if (ix
== 0x7ff00000) {
1025 if (iy
== 0x7ff00000) {
1027 case 0: return pi
/ 4; /* atan(+INF,+INF) */
1028 case 1: return -pi
/ 4; /* atan(-INF,+INF) */
1029 case 2: return 3 * pi
/ 4; /* atan(+INF,-INF) */
1030 case 3: return -3 * pi
/ 4; /* atan(-INF,-INF) */
1034 case 0: return 0.0; /* atan(+...,+INF) */
1035 case 1: return -0.0; /* atan(-...,+INF) */
1036 case 2: return pi
; /* atan(+...,-INF) */
1037 case 3: return -pi
; /* atan(-...,-INF) */
1041 /* |y/x| > 0x1p64 */
1042 if (ix
+ (64 << 20) < iy
|| iy
== 0x7ff00000)
1043 return m
& 1 ? -pi
/ 2 : pi
/ 2;
1045 /* z = atan(|y/x|) without spurious underflow */
1046 if ((m
& 2) && iy
+ (64 << 20) < ix
) /* |y/x| < 0x1p-64, x<0 */
1049 z
= atan(fabs(y
/ x
));
1051 case 0: return z
; /* atan(+,+) */
1052 case 1: return -z
; /* atan(-,+) */
1053 case 2: return pi
- (z
- pi_lo
); /* atan(+,-) */
1054 default: /* case 3 */
1055 return (z
- pi_lo
) - pi
; /* atan(-,-) */
1059 /*********************************************************************
1060 * MSVCRT_cos (MSVCRT.@)
1062 double CDECL
MSVCRT_cos( double x
)
1064 double ret
= cos(x
);
1065 if (!isfinite(x
)) return math_error(_DOMAIN
, "cos", x
, 0, ret
);
1069 /*********************************************************************
1070 * MSVCRT_cosh (MSVCRT.@)
1072 double CDECL
MSVCRT_cosh( double x
)
1074 double ret
= cosh(x
);
1075 if (isnan(x
)) return math_error(_DOMAIN
, "cosh", x
, 0, ret
);
1079 /*********************************************************************
1080 * MSVCRT_exp (MSVCRT.@)
1082 double CDECL
MSVCRT_exp( double x
)
1084 double ret
= exp(x
);
1085 if (isnan(x
)) return math_error(_DOMAIN
, "exp", x
, 0, ret
);
1086 if (isfinite(x
) && !ret
) return math_error(_UNDERFLOW
, "exp", x
, 0, ret
);
1087 if (isfinite(x
) && !isfinite(ret
)) return math_error(_OVERFLOW
, "exp", x
, 0, ret
);
1091 /*********************************************************************
1092 * MSVCRT_fmod (MSVCRT.@)
1094 double CDECL
MSVCRT_fmod( double x
, double y
)
1096 double ret
= fmod(x
, y
);
1097 if (!isfinite(x
) || !isfinite(y
)) return math_error(_DOMAIN
, "fmod", x
, y
, ret
);
1101 /*********************************************************************
1102 * MSVCRT_log (MSVCRT.@)
1104 double CDECL
MSVCRT_log( double x
)
1106 double ret
= log(x
);
1107 if (x
< 0.0) return math_error(_DOMAIN
, "log", x
, 0, ret
);
1108 if (x
== 0.0) return math_error(_SING
, "log", x
, 0, ret
);
1112 /*********************************************************************
1113 * MSVCRT_log10 (MSVCRT.@)
1115 double CDECL
MSVCRT_log10( double x
)
1117 double ret
= log10(x
);
1118 if (x
< 0.0) return math_error(_DOMAIN
, "log10", x
, 0, ret
);
1119 if (x
== 0.0) return math_error(_SING
, "log10", x
, 0, ret
);
1123 /*********************************************************************
1124 * MSVCRT_pow (MSVCRT.@)
1126 double CDECL
MSVCRT_pow( double x
, double y
)
1128 double z
= pow(x
,y
);
1129 if (x
< 0 && y
!= floor(y
))
1130 return math_error(_DOMAIN
, "pow", x
, y
, z
);
1131 if (!x
&& isfinite(y
) && y
< 0)
1132 return math_error(_SING
, "pow", x
, y
, z
);
1133 if (isfinite(x
) && isfinite(y
) && !isfinite(z
))
1134 return math_error(_OVERFLOW
, "pow", x
, y
, z
);
1135 if (x
&& isfinite(x
) && isfinite(y
) && !z
)
1136 return math_error(_UNDERFLOW
, "pow", x
, y
, z
);
1140 /*********************************************************************
1141 * MSVCRT_sin (MSVCRT.@)
1143 double CDECL
MSVCRT_sin( double x
)
1145 double ret
= sin(x
);
1146 if (!isfinite(x
)) return math_error(_DOMAIN
, "sin", x
, 0, ret
);
1150 /*********************************************************************
1151 * MSVCRT_sinh (MSVCRT.@)
1153 double CDECL
MSVCRT_sinh( double x
)
1155 double ret
= sinh(x
);
1156 if (isnan(x
)) return math_error(_DOMAIN
, "sinh", x
, 0, ret
);
1160 /*********************************************************************
1161 * MSVCRT_sqrt (MSVCRT.@)
1163 * Copied from musl: src/math/sqrt.c
1165 double CDECL
MSVCRT_sqrt( double x
)
1167 static const double tiny
= 1.0e-300;
1170 int sign
= 0x80000000;
1172 unsigned int r
,t1
,s1
,ix1
,q1
;
1175 ix
= *(ULONGLONG
*)&x
;
1179 /* take care of Inf and NaN */
1180 if (isnan(x
) || (isinf(x
) && x
> 0))
1183 /* take care of zero */
1185 if (((ix0
& ~sign
) | ix1
) == 0)
1186 return x
; /* sqrt(+-0) = +-0 */
1188 return math_error(_DOMAIN
, "sqrt", x
, 0, (x
- x
) / (x
- x
));
1192 if (m
== 0) { /* subnormal x */
1198 for (i
=0; (ix0
& 0x00100000) == 0; i
++)
1201 ix0
|= ix1
>> (32 - i
);
1204 m
-= 1023; /* unbias exponent */
1205 ix0
= (ix0
& 0x000fffff) | 0x00100000;
1206 if (m
& 1) { /* odd m, double x to make it even */
1207 ix0
+= ix0
+ ((ix1
& sign
) >> 31);
1210 m
>>= 1; /* m = [m/2] */
1212 /* generate sqrt(x) bit by bit */
1213 ix0
+= ix0
+ ((ix1
& sign
) >> 31);
1215 q
= q1
= s0
= s1
= 0; /* [q,q1] = sqrt(x) */
1216 r
= 0x00200000; /* r = moving bit from right to left */
1225 ix0
+= ix0
+ ((ix1
& sign
) >> 31);
1234 if (t
< ix0
|| (t
== ix0
&& t1
<= ix1
)) {
1236 if ((t1
&sign
) == sign
&& (s1
& sign
) == 0)
1244 ix0
+= ix0
+ ((ix1
& sign
) >> 31);
1249 /* use floating add to find out rounding direction */
1250 if ((ix0
| ix1
) != 0) {
1251 z
= 1.0 - tiny
; /* raise inexact flag */
1254 if (q1
== (unsigned int)0xffffffff) {
1257 } else if (z
> 1.0) {
1258 if (q1
== (unsigned int)0xfffffffe)
1265 ix0
= (q
>> 1) + 0x3fe00000;
1269 ix
= ix0
+ ((unsigned int)m
<< 20);
1272 return *(double*)&ix
;
1275 /*********************************************************************
1276 * MSVCRT_tan (MSVCRT.@)
1278 double CDECL
MSVCRT_tan( double x
)
1280 double ret
= tan(x
);
1281 if (!isfinite(x
)) return math_error(_DOMAIN
, "tan", x
, 0, ret
);
1285 /*********************************************************************
1286 * MSVCRT_tanh (MSVCRT.@)
1288 double CDECL
MSVCRT_tanh( double x
)
1290 double ret
= tanh(x
);
1291 if (isnan(x
)) return math_error(_DOMAIN
, "tanh", x
, 0, ret
);
1296 #if defined(__GNUC__) && defined(__i386__)
1298 #define CREATE_FPU_FUNC1(name, call) \
1299 __ASM_GLOBAL_FUNC(name, \
1301 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") \
1302 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t") \
1303 "movl %esp, %ebp\n\t" \
1304 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t") \
1305 "subl $68, %esp\n\t" /* sizeof(double)*8 + sizeof(int) */ \
1306 "fstpl (%esp)\n\t" /* store function argument */ \
1308 "movl $1, %ecx\n\t" /* empty FPU stack */ \
1312 "and $0x4500, %ax\n\t" \
1313 "cmp $0x4100, %ax\n\t" \
1315 "fstpl (%esp,%ecx,8)\n\t" \
1320 "movl %ecx, -4(%ebp)\n\t" \
1321 "call " __ASM_NAME( #call ) "\n\t" \
1322 "movl -4(%ebp), %ecx\n\t" \
1323 "fstpl (%esp)\n\t" /* save result */ \
1324 "3:\n\t" /* restore FPU stack */ \
1326 "fldl (%esp,%ecx,8)\n\t" \
1327 "cmpl $0, %ecx\n\t" \
1330 __ASM_CFI(".cfi_def_cfa %esp,4\n\t") \
1331 __ASM_CFI(".cfi_same_value %ebp\n\t") \
1334 #define CREATE_FPU_FUNC2(name, call) \
1335 __ASM_GLOBAL_FUNC(name, \
1337 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") \
1338 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t") \
1339 "movl %esp, %ebp\n\t" \
1340 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t") \
1341 "subl $68, %esp\n\t" /* sizeof(double)*8 + sizeof(int) */ \
1342 "fstpl 8(%esp)\n\t" /* store function argument */ \
1344 "fstpl (%esp)\n\t" \
1346 "movl $2, %ecx\n\t" /* empty FPU stack */ \
1350 "and $0x4500, %ax\n\t" \
1351 "cmp $0x4100, %ax\n\t" \
1353 "fstpl (%esp,%ecx,8)\n\t" \
1358 "movl %ecx, -4(%ebp)\n\t" \
1359 "call " __ASM_NAME( #call ) "\n\t" \
1360 "movl -4(%ebp), %ecx\n\t" \
1361 "fstpl 8(%esp)\n\t" /* save result */ \
1362 "3:\n\t" /* restore FPU stack */ \
1364 "fldl (%esp,%ecx,8)\n\t" \
1365 "cmpl $1, %ecx\n\t" \
1368 __ASM_CFI(".cfi_def_cfa %esp,4\n\t") \
1369 __ASM_CFI(".cfi_same_value %ebp\n\t") \
1372 CREATE_FPU_FUNC1(_CIacos
, MSVCRT_acos
)
1373 CREATE_FPU_FUNC1(_CIasin
, MSVCRT_asin
)
1374 CREATE_FPU_FUNC1(_CIatan
, MSVCRT_atan
)
1375 CREATE_FPU_FUNC2(_CIatan2
, MSVCRT_atan2
)
1376 CREATE_FPU_FUNC1(_CIcos
, MSVCRT_cos
)
1377 CREATE_FPU_FUNC1(_CIcosh
, MSVCRT_cosh
)
1378 CREATE_FPU_FUNC1(_CIexp
, MSVCRT_exp
)
1379 CREATE_FPU_FUNC2(_CIfmod
, MSVCRT_fmod
)
1380 CREATE_FPU_FUNC1(_CIlog
, MSVCRT_log
)
1381 CREATE_FPU_FUNC1(_CIlog10
, MSVCRT_log10
)
1382 CREATE_FPU_FUNC2(_CIpow
, MSVCRT_pow
)
1383 CREATE_FPU_FUNC1(_CIsin
, MSVCRT_sin
)
1384 CREATE_FPU_FUNC1(_CIsinh
, MSVCRT_sinh
)
1385 CREATE_FPU_FUNC1(_CIsqrt
, MSVCRT_sqrt
)
1386 CREATE_FPU_FUNC1(_CItan
, MSVCRT_tan
)
1387 CREATE_FPU_FUNC1(_CItanh
, MSVCRT_tanh
)
1389 __ASM_GLOBAL_FUNC(MSVCRT__ftol
,
1391 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
1392 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
1393 "movl %esp, %ebp\n\t"
1394 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
1395 "subl $12, %esp\n\t" /* sizeof(LONGLONG) + 2*sizeof(WORD) */
1397 "mov (%esp), %ax\n\t"
1398 "or $0xc00, %ax\n\t"
1399 "mov %ax, 2(%esp)\n\t"
1401 "fistpq 4(%esp)\n\t"
1403 "movl 4(%esp), %eax\n\t"
1404 "movl 8(%esp), %edx\n\t"
1406 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
1407 __ASM_CFI(".cfi_same_value %ebp\n\t")
1410 #endif /* defined(__GNUC__) && defined(__i386__) */
1412 /*********************************************************************
1413 * _fpclass (MSVCRT.@)
1415 int CDECL
MSVCRT__fpclass(double num
)
1417 union { double f
; UINT64 i
; } u
= { num
};
1418 int e
= u
.i
>> 52 & 0x7ff;
1424 if (u
.i
<< 1) return s
? MSVCRT__FPCLASS_ND
: MSVCRT__FPCLASS_PD
;
1425 return s
? MSVCRT__FPCLASS_NZ
: MSVCRT__FPCLASS_PZ
;
1427 if (u
.i
<< 12) return ((u
.i
>> 51) & 1) ? MSVCRT__FPCLASS_QNAN
: MSVCRT__FPCLASS_SNAN
;
1428 return s
? MSVCRT__FPCLASS_NINF
: MSVCRT__FPCLASS_PINF
;
1430 return s
? MSVCRT__FPCLASS_NN
: MSVCRT__FPCLASS_PN
;
1434 /*********************************************************************
1437 unsigned int CDECL
_rotl(unsigned int num
, int shift
)
1440 return (num
<< shift
) | (num
>> (32-shift
));
1443 /*********************************************************************
1446 MSVCRT_ulong CDECL
MSVCRT__lrotl(MSVCRT_ulong num
, int shift
)
1449 return (num
<< shift
) | (num
>> (32-shift
));
1452 /*********************************************************************
1455 MSVCRT_ulong CDECL
MSVCRT__lrotr(MSVCRT_ulong num
, int shift
)
1458 return (num
>> shift
) | (num
<< (32-shift
));
1461 /*********************************************************************
1464 unsigned int CDECL
_rotr(unsigned int num
, int shift
)
1467 return (num
>> shift
) | (num
<< (32-shift
));
1470 /*********************************************************************
1471 * _rotl64 (MSVCRT.@)
1473 unsigned __int64 CDECL
_rotl64(unsigned __int64 num
, int shift
)
1476 return (num
<< shift
) | (num
>> (64-shift
));
1479 /*********************************************************************
1480 * _rotr64 (MSVCRT.@)
1482 unsigned __int64 CDECL
_rotr64(unsigned __int64 num
, int shift
)
1485 return (num
>> shift
) | (num
<< (64-shift
));
1488 /*********************************************************************
1491 int CDECL
MSVCRT_abs( int n
)
1493 return n
>= 0 ? n
: -n
;
1496 /*********************************************************************
1499 MSVCRT_long CDECL
MSVCRT_labs( MSVCRT_long n
)
1501 return n
>= 0 ? n
: -n
;
1505 /*********************************************************************
1506 * llabs (MSVCR100.@)
1508 MSVCRT_longlong CDECL
MSVCRT_llabs( MSVCRT_longlong n
)
1510 return n
>= 0 ? n
: -n
;
1515 /*********************************************************************
1516 * imaxabs (MSVCR120.@)
1518 MSVCRT_intmax_t CDECL
MSVCRT_imaxabs( MSVCRT_intmax_t n
)
1520 return n
>= 0 ? n
: -n
;
1524 /*********************************************************************
1527 __int64 CDECL
_abs64( __int64 n
)
1529 return n
>= 0 ? n
: -n
;
1532 /*********************************************************************
1535 double CDECL
MSVCRT__logb(double num
)
1537 double ret
= logb(num
);
1538 if (isnan(num
)) return math_error(_DOMAIN
, "_logb", num
, 0, ret
);
1539 if (!num
) return math_error(_SING
, "_logb", num
, 0, ret
);
1543 /*********************************************************************
1546 double CDECL
_hypot(double x
, double y
)
1548 /* FIXME: errno handling */
1549 return hypot( x
, y
);
1552 /*********************************************************************
1553 * _hypotf (MSVCRT.@)
1555 float CDECL
MSVCRT__hypotf(float x
, float y
)
1557 /* FIXME: errno handling */
1558 return hypotf( x
, y
);
1561 /*********************************************************************
1564 double CDECL
MSVCRT_ceil( double x
)
1569 /*********************************************************************
1572 double CDECL
MSVCRT_floor( double x
)
1577 /*********************************************************************
1580 double CDECL
MSVCRT_fma( double x
, double y
, double z
)
1583 double w
= fma(x
, y
, z
);
1585 double w
= x
* y
+ z
;
1587 if ((isinf(x
) && y
== 0) || (x
== 0 && isinf(y
))) *MSVCRT__errno() = MSVCRT_EDOM
;
1588 else if (isinf(x
) && isinf(z
) && x
!= z
) *MSVCRT__errno() = MSVCRT_EDOM
;
1589 else if (isinf(y
) && isinf(z
) && y
!= z
) *MSVCRT__errno() = MSVCRT_EDOM
;
1593 /*********************************************************************
1596 float CDECL
MSVCRT_fmaf( float x
, float y
, float z
)
1599 float w
= fmaf(x
, y
, z
);
1601 float w
= x
* y
+ z
;
1603 if ((isinf(x
) && y
== 0) || (x
== 0 && isinf(y
))) *MSVCRT__errno() = MSVCRT_EDOM
;
1604 else if (isinf(x
) && isinf(z
) && x
!= z
) *MSVCRT__errno() = MSVCRT_EDOM
;
1605 else if (isinf(y
) && isinf(z
) && y
!= z
) *MSVCRT__errno() = MSVCRT_EDOM
;
1609 /*********************************************************************
1612 * Copied from musl: src/math/fabsf.c
1614 double CDECL
MSVCRT_fabs( double x
)
1616 union { double f
; UINT64 i
; } u
= { x
};
1621 /*********************************************************************
1624 double CDECL
MSVCRT_frexp( double x
, int *exp
)
1626 return frexp( x
, exp
);
1629 /*********************************************************************
1632 double CDECL
MSVCRT_modf( double x
, double *iptr
)
1634 return modf( x
, iptr
);
1637 /**********************************************************************
1638 * _statusfp2 (MSVCRT.@)
1640 * Not exported by native msvcrt, added in msvcr80.
1642 #if defined(__i386__) || defined(__x86_64__)
1643 void CDECL
_statusfp2( unsigned int *x86_sw
, unsigned int *sse2_sw
)
1647 unsigned long fpword
;
1651 __asm__
__volatile__( "fstsw %0" : "=m" (fpword
) );
1653 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
1654 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
1655 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
1656 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
1657 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
1658 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
1662 if (!sse2_sw
) return;
1666 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
1668 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
1669 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
1670 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
1671 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
1672 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
1673 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
1678 FIXME( "not implemented\n" );
1683 /**********************************************************************
1684 * _statusfp (MSVCRT.@)
1686 unsigned int CDECL
_statusfp(void)
1688 unsigned int flags
= 0;
1689 #if defined(__i386__) || defined(__x86_64__)
1690 unsigned int x86_sw
, sse2_sw
;
1692 _statusfp2( &x86_sw
, &sse2_sw
);
1693 /* FIXME: there's no definition for ambiguous status, just return all status bits for now */
1694 flags
= x86_sw
| sse2_sw
;
1695 #elif defined(__aarch64__)
1698 __asm__
__volatile__( "mrs %0, fpsr" : "=r" (fpsr
) );
1699 if (fpsr
& 0x1) flags
|= MSVCRT__SW_INVALID
;
1700 if (fpsr
& 0x2) flags
|= MSVCRT__SW_ZERODIVIDE
;
1701 if (fpsr
& 0x4) flags
|= MSVCRT__SW_OVERFLOW
;
1702 if (fpsr
& 0x8) flags
|= MSVCRT__SW_UNDERFLOW
;
1703 if (fpsr
& 0x10) flags
|= MSVCRT__SW_INEXACT
;
1704 if (fpsr
& 0x80) flags
|= MSVCRT__SW_DENORMAL
;
1706 FIXME( "not implemented\n" );
1711 /*********************************************************************
1712 * _clearfp (MSVCRT.@)
1714 unsigned int CDECL
_clearfp(void)
1716 unsigned int flags
= 0;
1717 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1718 unsigned long fpword
;
1720 __asm__
__volatile__( "fnstsw %0; fnclex" : "=m" (fpword
) );
1721 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
1722 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
1723 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
1724 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
1725 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
1726 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
1730 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
1731 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
1732 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
1733 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
1734 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
1735 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
1736 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
1738 __asm__
__volatile__( "ldmxcsr %0" : : "m" (fpword
) );
1740 #elif defined(__aarch64__)
1743 __asm__
__volatile__( "mrs %0, fpsr" : "=r" (fpsr
) );
1744 if (fpsr
& 0x1) flags
|= MSVCRT__SW_INVALID
;
1745 if (fpsr
& 0x2) flags
|= MSVCRT__SW_ZERODIVIDE
;
1746 if (fpsr
& 0x4) flags
|= MSVCRT__SW_OVERFLOW
;
1747 if (fpsr
& 0x8) flags
|= MSVCRT__SW_UNDERFLOW
;
1748 if (fpsr
& 0x10) flags
|= MSVCRT__SW_INEXACT
;
1749 if (fpsr
& 0x80) flags
|= MSVCRT__SW_DENORMAL
;
1751 __asm__
__volatile__( "msr fpsr, %0" :: "r" (fpsr
) );
1753 FIXME( "not implemented\n" );
1758 /*********************************************************************
1759 * __fpecode (MSVCRT.@)
1761 int * CDECL
__fpecode(void)
1763 return &msvcrt_get_thread_data()->fpecode
;
1766 /*********************************************************************
1769 double CDECL
MSVCRT_ldexp(double num
, MSVCRT_long exp
)
1771 double z
= ldexp(num
,exp
);
1773 if (isfinite(num
) && !isfinite(z
))
1774 return math_error(_OVERFLOW
, "ldexp", num
, exp
, z
);
1775 if (num
&& isfinite(num
) && !z
)
1776 return math_error(_UNDERFLOW
, "ldexp", num
, exp
, z
);
1777 if (z
== 0 && signbit(z
))
1778 z
= 0.0; /* Convert -0 -> +0 */
1782 /*********************************************************************
1785 double CDECL
MSVCRT__cabs(struct MSVCRT__complex num
)
1787 return sqrt(num
.x
* num
.x
+ num
.y
* num
.y
);
1790 /*********************************************************************
1791 * _chgsign (MSVCRT.@)
1793 double CDECL
MSVCRT__chgsign(double num
)
1795 union { double f
; UINT64 i
; } u
= { num
};
1800 /*********************************************************************
1801 * __control87_2 (MSVCR80.@)
1803 * Not exported by native msvcrt, added in msvcr80.
1806 int CDECL
__control87_2( unsigned int newval
, unsigned int mask
,
1807 unsigned int *x86_cw
, unsigned int *sse2_cw
)
1810 unsigned long fpword
;
1812 unsigned int old_flags
;
1816 __asm__
__volatile__( "fstcw %0" : "=m" (fpword
) );
1818 /* Convert into mask constants */
1820 if (fpword
& 0x1) flags
|= MSVCRT__EM_INVALID
;
1821 if (fpword
& 0x2) flags
|= MSVCRT__EM_DENORMAL
;
1822 if (fpword
& 0x4) flags
|= MSVCRT__EM_ZERODIVIDE
;
1823 if (fpword
& 0x8) flags
|= MSVCRT__EM_OVERFLOW
;
1824 if (fpword
& 0x10) flags
|= MSVCRT__EM_UNDERFLOW
;
1825 if (fpword
& 0x20) flags
|= MSVCRT__EM_INEXACT
;
1826 switch (fpword
& 0xc00)
1828 case 0xc00: flags
|= MSVCRT__RC_UP
|MSVCRT__RC_DOWN
; break;
1829 case 0x800: flags
|= MSVCRT__RC_UP
; break;
1830 case 0x400: flags
|= MSVCRT__RC_DOWN
; break;
1832 switch (fpword
& 0x300)
1834 case 0x0: flags
|= MSVCRT__PC_24
; break;
1835 case 0x200: flags
|= MSVCRT__PC_53
; break;
1836 case 0x300: flags
|= MSVCRT__PC_64
; break;
1838 if (fpword
& 0x1000) flags
|= MSVCRT__IC_AFFINE
;
1840 TRACE( "x86 flags=%08x newval=%08x mask=%08x\n", flags
, newval
, mask
);
1843 flags
= (flags
& ~mask
) | (newval
& mask
);
1845 /* Convert (masked) value back to fp word */
1847 if (flags
& MSVCRT__EM_INVALID
) fpword
|= 0x1;
1848 if (flags
& MSVCRT__EM_DENORMAL
) fpword
|= 0x2;
1849 if (flags
& MSVCRT__EM_ZERODIVIDE
) fpword
|= 0x4;
1850 if (flags
& MSVCRT__EM_OVERFLOW
) fpword
|= 0x8;
1851 if (flags
& MSVCRT__EM_UNDERFLOW
) fpword
|= 0x10;
1852 if (flags
& MSVCRT__EM_INEXACT
) fpword
|= 0x20;
1853 switch (flags
& MSVCRT__MCW_RC
)
1855 case MSVCRT__RC_UP
|MSVCRT__RC_DOWN
: fpword
|= 0xc00; break;
1856 case MSVCRT__RC_UP
: fpword
|= 0x800; break;
1857 case MSVCRT__RC_DOWN
: fpword
|= 0x400; break;
1859 switch (flags
& MSVCRT__MCW_PC
)
1861 case MSVCRT__PC_64
: fpword
|= 0x300; break;
1862 case MSVCRT__PC_53
: fpword
|= 0x200; break;
1863 case MSVCRT__PC_24
: fpword
|= 0x0; break;
1865 if (flags
& MSVCRT__IC_AFFINE
) fpword
|= 0x1000;
1867 __asm__
__volatile__( "fldcw %0" : : "m" (fpword
) );
1872 if (!sse2_cw
) return 1;
1876 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
1878 /* Convert into mask constants */
1880 if (fpword
& 0x80) flags
|= MSVCRT__EM_INVALID
;
1881 if (fpword
& 0x100) flags
|= MSVCRT__EM_DENORMAL
;
1882 if (fpword
& 0x200) flags
|= MSVCRT__EM_ZERODIVIDE
;
1883 if (fpword
& 0x400) flags
|= MSVCRT__EM_OVERFLOW
;
1884 if (fpword
& 0x800) flags
|= MSVCRT__EM_UNDERFLOW
;
1885 if (fpword
& 0x1000) flags
|= MSVCRT__EM_INEXACT
;
1886 switch (fpword
& 0x6000)
1888 case 0x6000: flags
|= MSVCRT__RC_UP
|MSVCRT__RC_DOWN
; break;
1889 case 0x4000: flags
|= MSVCRT__RC_UP
; break;
1890 case 0x2000: flags
|= MSVCRT__RC_DOWN
; break;
1892 switch (fpword
& 0x8040)
1894 case 0x0040: flags
|= MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS
; break;
1895 case 0x8000: flags
|= MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS
; break;
1896 case 0x8040: flags
|= MSVCRT__DN_FLUSH
; break;
1899 TRACE( "sse2 flags=%08x newval=%08x mask=%08x\n", flags
, newval
, mask
);
1903 mask
&= MSVCRT__MCW_EM
| MSVCRT__MCW_RC
| MSVCRT__MCW_DN
;
1904 flags
= (flags
& ~mask
) | (newval
& mask
);
1906 if (flags
!= old_flags
)
1908 /* Convert (masked) value back to fp word */
1910 if (flags
& MSVCRT__EM_INVALID
) fpword
|= 0x80;
1911 if (flags
& MSVCRT__EM_DENORMAL
) fpword
|= 0x100;
1912 if (flags
& MSVCRT__EM_ZERODIVIDE
) fpword
|= 0x200;
1913 if (flags
& MSVCRT__EM_OVERFLOW
) fpword
|= 0x400;
1914 if (flags
& MSVCRT__EM_UNDERFLOW
) fpword
|= 0x800;
1915 if (flags
& MSVCRT__EM_INEXACT
) fpword
|= 0x1000;
1916 switch (flags
& MSVCRT__MCW_RC
)
1918 case MSVCRT__RC_UP
|MSVCRT__RC_DOWN
: fpword
|= 0x6000; break;
1919 case MSVCRT__RC_UP
: fpword
|= 0x4000; break;
1920 case MSVCRT__RC_DOWN
: fpword
|= 0x2000; break;
1922 switch (flags
& MSVCRT__MCW_DN
)
1924 case MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS
: fpword
|= 0x0040; break;
1925 case MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS
: fpword
|= 0x8000; break;
1926 case MSVCRT__DN_FLUSH
: fpword
|= 0x8040; break;
1928 __asm__
__volatile__( "ldmxcsr %0" : : "m" (fpword
) );
1937 FIXME( "not implemented\n" );
1943 /*********************************************************************
1944 * _control87 (MSVCRT.@)
1946 unsigned int CDECL
_control87(unsigned int newval
, unsigned int mask
)
1948 unsigned int flags
= 0;
1950 unsigned int sse2_cw
;
1952 __control87_2( newval
, mask
, &flags
, &sse2_cw
);
1954 if ((flags
^ sse2_cw
) & (MSVCRT__MCW_EM
| MSVCRT__MCW_RC
)) flags
|= MSVCRT__EM_AMBIGUOUS
;
1956 #elif defined(__x86_64__)
1957 unsigned long fpword
;
1958 unsigned int old_flags
;
1960 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
1961 if (fpword
& 0x80) flags
|= MSVCRT__EM_INVALID
;
1962 if (fpword
& 0x100) flags
|= MSVCRT__EM_DENORMAL
;
1963 if (fpword
& 0x200) flags
|= MSVCRT__EM_ZERODIVIDE
;
1964 if (fpword
& 0x400) flags
|= MSVCRT__EM_OVERFLOW
;
1965 if (fpword
& 0x800) flags
|= MSVCRT__EM_UNDERFLOW
;
1966 if (fpword
& 0x1000) flags
|= MSVCRT__EM_INEXACT
;
1967 switch (fpword
& 0x6000)
1969 case 0x6000: flags
|= MSVCRT__RC_CHOP
; break;
1970 case 0x4000: flags
|= MSVCRT__RC_UP
; break;
1971 case 0x2000: flags
|= MSVCRT__RC_DOWN
; break;
1973 switch (fpword
& 0x8040)
1975 case 0x0040: flags
|= MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS
; break;
1976 case 0x8000: flags
|= MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS
; break;
1977 case 0x8040: flags
|= MSVCRT__DN_FLUSH
; break;
1980 mask
&= MSVCRT__MCW_EM
| MSVCRT__MCW_RC
| MSVCRT__MCW_DN
;
1981 flags
= (flags
& ~mask
) | (newval
& mask
);
1982 if (flags
!= old_flags
)
1985 if (flags
& MSVCRT__EM_INVALID
) fpword
|= 0x80;
1986 if (flags
& MSVCRT__EM_DENORMAL
) fpword
|= 0x100;
1987 if (flags
& MSVCRT__EM_ZERODIVIDE
) fpword
|= 0x200;
1988 if (flags
& MSVCRT__EM_OVERFLOW
) fpword
|= 0x400;
1989 if (flags
& MSVCRT__EM_UNDERFLOW
) fpword
|= 0x800;
1990 if (flags
& MSVCRT__EM_INEXACT
) fpword
|= 0x1000;
1991 switch (flags
& MSVCRT__MCW_RC
)
1993 case MSVCRT__RC_CHOP
: fpword
|= 0x6000; break;
1994 case MSVCRT__RC_UP
: fpword
|= 0x4000; break;
1995 case MSVCRT__RC_DOWN
: fpword
|= 0x2000; break;
1997 switch (flags
& MSVCRT__MCW_DN
)
1999 case MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS
: fpword
|= 0x0040; break;
2000 case MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS
: fpword
|= 0x8000; break;
2001 case MSVCRT__DN_FLUSH
: fpword
|= 0x8040; break;
2003 __asm__
__volatile__( "ldmxcsr %0" :: "m" (fpword
) );
2005 #elif defined(__aarch64__)
2008 __asm__
__volatile__( "mrs %0, fpcr" : "=r" (fpcr
) );
2009 if (!(fpcr
& 0x100)) flags
|= MSVCRT__EM_INVALID
;
2010 if (!(fpcr
& 0x200)) flags
|= MSVCRT__EM_ZERODIVIDE
;
2011 if (!(fpcr
& 0x400)) flags
|= MSVCRT__EM_OVERFLOW
;
2012 if (!(fpcr
& 0x800)) flags
|= MSVCRT__EM_UNDERFLOW
;
2013 if (!(fpcr
& 0x1000)) flags
|= MSVCRT__EM_INEXACT
;
2014 if (!(fpcr
& 0x8000)) flags
|= MSVCRT__EM_DENORMAL
;
2015 switch (fpcr
& 0xc00000)
2017 case 0x400000: flags
|= MSVCRT__RC_UP
; break;
2018 case 0x800000: flags
|= MSVCRT__RC_DOWN
; break;
2019 case 0xc00000: flags
|= MSVCRT__RC_CHOP
; break;
2021 flags
= (flags
& ~mask
) | (newval
& mask
);
2022 fpcr
&= ~0xc09f00ul
;
2023 if (!(flags
& MSVCRT__EM_INVALID
)) fpcr
|= 0x100;
2024 if (!(flags
& MSVCRT__EM_ZERODIVIDE
)) fpcr
|= 0x200;
2025 if (!(flags
& MSVCRT__EM_OVERFLOW
)) fpcr
|= 0x400;
2026 if (!(flags
& MSVCRT__EM_UNDERFLOW
)) fpcr
|= 0x800;
2027 if (!(flags
& MSVCRT__EM_INEXACT
)) fpcr
|= 0x1000;
2028 if (!(flags
& MSVCRT__EM_DENORMAL
)) fpcr
|= 0x8000;
2029 switch (flags
& MSVCRT__MCW_RC
)
2031 case MSVCRT__RC_CHOP
: fpcr
|= 0xc00000; break;
2032 case MSVCRT__RC_UP
: fpcr
|= 0x400000; break;
2033 case MSVCRT__RC_DOWN
: fpcr
|= 0x800000; break;
2035 __asm__
__volatile__( "msr fpcr, %0" :: "r" (fpcr
) );
2037 FIXME( "not implemented\n" );
2042 /*********************************************************************
2043 * _controlfp (MSVCRT.@)
2045 unsigned int CDECL
_controlfp(unsigned int newval
, unsigned int mask
)
2047 return _control87( newval
, mask
& ~MSVCRT__EM_DENORMAL
);
2050 /*********************************************************************
2051 * _set_controlfp (MSVCRT.@)
2053 void CDECL
_set_controlfp( unsigned int newval
, unsigned int mask
)
2055 _controlfp( newval
, mask
);
2058 /*********************************************************************
2059 * _controlfp_s (MSVCRT.@)
2061 int CDECL
_controlfp_s(unsigned int *cur
, unsigned int newval
, unsigned int mask
)
2063 static const unsigned int all_flags
= (MSVCRT__MCW_EM
| MSVCRT__MCW_IC
| MSVCRT__MCW_RC
|
2064 MSVCRT__MCW_PC
| MSVCRT__MCW_DN
);
2067 if (!MSVCRT_CHECK_PMT( !(newval
& mask
& ~all_flags
) ))
2069 if (cur
) *cur
= _controlfp( 0, 0 ); /* retrieve it anyway */
2070 return MSVCRT_EINVAL
;
2072 val
= _controlfp( newval
, mask
);
2073 if (cur
) *cur
= val
;
2078 /*********************************************************************
2079 * fegetenv (MSVCR120.@)
2081 int CDECL
MSVCRT_fegetenv(MSVCRT_fenv_t
*env
)
2083 env
->control
= _controlfp(0, 0) & (MSVCRT__EM_INEXACT
| MSVCRT__EM_UNDERFLOW
|
2084 MSVCRT__EM_OVERFLOW
| MSVCRT__EM_ZERODIVIDE
| MSVCRT__EM_INVALID
);
2085 env
->status
= _statusfp();
2091 /*********************************************************************
2092 * __fpe_flt_rounds (UCRTBASE.@)
2094 int CDECL
__fpe_flt_rounds(void)
2096 unsigned int fpc
= _controlfp(0, 0) & MSVCRT__RC_CHOP
;
2101 case MSVCRT__RC_CHOP
: return 0;
2102 case MSVCRT__RC_NEAR
: return 1;
2103 case MSVCRT__RC_UP
: return 2;
2111 /*********************************************************************
2112 * fegetround (MSVCR120.@)
2114 int CDECL
MSVCRT_fegetround(void)
2116 return _controlfp(0, 0) & MSVCRT__RC_CHOP
;
2119 /*********************************************************************
2120 * fesetround (MSVCR120.@)
2122 int CDECL
MSVCRT_fesetround(int round_mode
)
2124 if (round_mode
& (~MSVCRT__RC_CHOP
))
2126 _controlfp(round_mode
, MSVCRT__RC_CHOP
);
2130 #endif /* _MSVCR_VER>=120 */
2132 /*********************************************************************
2133 * _copysign (MSVCRT.@)
2135 * Copied from musl: src/math/copysign.c
2137 double CDECL
MSVCRT__copysign( double x
, double y
)
2139 union { double f
; UINT64 i
; } ux
= { x
}, uy
= { y
};
2141 ux
.i
|= uy
.i
& 1ull << 63;
2145 /*********************************************************************
2146 * _finite (MSVCRT.@)
2148 int CDECL
MSVCRT__finite(double num
)
2150 union { double f
; UINT64 i
; } u
= { num
};
2151 return (u
.i
& ~0ull >> 1) < 0x7ffull
<< 52;
2154 /*********************************************************************
2155 * _fpreset (MSVCRT.@)
2157 void CDECL
_fpreset(void)
2159 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2160 const unsigned int x86_cw
= 0x27f;
2161 __asm__
__volatile__( "fninit; fldcw %0" : : "m" (x86_cw
) );
2164 const unsigned long sse2_cw
= 0x1f80;
2165 __asm__
__volatile__( "ldmxcsr %0" : : "m" (sse2_cw
) );
2168 FIXME( "not implemented\n" );
2173 /*********************************************************************
2174 * fesetenv (MSVCR120.@)
2176 int CDECL
MSVCRT_fesetenv(const MSVCRT_fenv_t
*env
)
2178 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2186 DWORD instruction_pointer
;
2194 TRACE( "(%p)\n", env
);
2196 if (!env
->control
&& !env
->status
) {
2201 __asm__
__volatile__( "fnstenv %0" : "=m" (fenv
) );
2203 fenv
.control_word
&= ~0x3d;
2204 if (env
->control
& MSVCRT__EM_INVALID
) fenv
.control_word
|= 0x1;
2205 if (env
->control
& MSVCRT__EM_ZERODIVIDE
) fenv
.control_word
|= 0x4;
2206 if (env
->control
& MSVCRT__EM_OVERFLOW
) fenv
.control_word
|= 0x8;
2207 if (env
->control
& MSVCRT__EM_UNDERFLOW
) fenv
.control_word
|= 0x10;
2208 if (env
->control
& MSVCRT__EM_INEXACT
) fenv
.control_word
|= 0x20;
2210 fenv
.status_word
&= ~0x3d;
2211 if (env
->status
& MSVCRT__SW_INVALID
) fenv
.status_word
|= 0x1;
2212 if (env
->status
& MSVCRT__SW_ZERODIVIDE
) fenv
.status_word
|= 0x4;
2213 if (env
->status
& MSVCRT__SW_OVERFLOW
) fenv
.status_word
|= 0x8;
2214 if (env
->status
& MSVCRT__SW_UNDERFLOW
) fenv
.status_word
|= 0x10;
2215 if (env
->status
& MSVCRT__SW_INEXACT
) fenv
.status_word
|= 0x20;
2217 __asm__
__volatile__( "fldenv %0" : : "m" (fenv
) : "st", "st(1)",
2218 "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)" );
2224 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
2226 if (env
->control
& MSVCRT__EM_INVALID
) fpword
|= 0x80;
2227 if (env
->control
& MSVCRT__EM_ZERODIVIDE
) fpword
|= 0x200;
2228 if (env
->control
& MSVCRT__EM_OVERFLOW
) fpword
|= 0x400;
2229 if (env
->control
& MSVCRT__EM_UNDERFLOW
) fpword
|= 0x800;
2230 if (env
->control
& MSVCRT__EM_INEXACT
) fpword
|= 0x1000;
2231 __asm__
__volatile__( "ldmxcsr %0" : : "m" (fpword
) );
2236 FIXME( "not implemented\n" );
2242 /*********************************************************************
2245 int CDECL
MSVCRT__isnan(double num
)
2247 union { double f
; UINT64 i
; } u
= { num
};
2248 return (u
.i
& ~0ull >> 1) > 0x7ffull
<< 52;
2251 /*********************************************************************
2254 double CDECL
MSVCRT__j0(double num
)
2256 /* FIXME: errno handling */
2260 FIXME("not implemented\n");
2265 /*********************************************************************
2268 double CDECL
MSVCRT__j1(double num
)
2270 /* FIXME: errno handling */
2274 FIXME("not implemented\n");
2279 /*********************************************************************
2282 double CDECL
MSVCRT__jn(int n
, double num
)
2284 /* FIXME: errno handling */
2288 FIXME("not implemented\n");
2293 /*********************************************************************
2296 double CDECL
MSVCRT__y0(double num
)
2299 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
2302 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
2304 *MSVCRT__errno() = MSVCRT_EDOM
;
2308 FIXME("not implemented\n");
2314 /*********************************************************************
2317 double CDECL
MSVCRT__y1(double num
)
2320 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
2323 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
2325 *MSVCRT__errno() = MSVCRT_EDOM
;
2329 FIXME("not implemented\n");
2335 /*********************************************************************
2338 double CDECL
MSVCRT__yn(int order
, double num
)
2341 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
2343 retval
= yn(order
,num
);
2344 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
2346 *MSVCRT__errno() = MSVCRT_EDOM
;
2350 FIXME("not implemented\n");
2358 /*********************************************************************
2359 * _nearbyint (MSVCR120.@)
2361 double CDECL
MSVCRT_nearbyint(double num
)
2363 #ifdef HAVE_NEARBYINT
2364 return nearbyint(num
);
2366 return num
>= 0 ? floor(num
+ 0.5) : ceil(num
- 0.5);
2370 /*********************************************************************
2371 * _nearbyintf (MSVCR120.@)
2373 float CDECL
MSVCRT_nearbyintf(float num
)
2375 #ifdef HAVE_NEARBYINTF
2376 return nearbyintf(num
);
2378 return MSVCRT_nearbyint(num
);
2382 /*********************************************************************
2383 * nexttoward (MSVCR120.@)
2385 double CDECL
MSVCRT_nexttoward(double num
, double next
)
2387 #ifdef HAVE_NEXTTOWARD
2388 double ret
= nexttoward(num
, next
);
2389 if (!(MSVCRT__fpclass(ret
) & (MSVCRT__FPCLASS_PN
| MSVCRT__FPCLASS_NN
2390 | MSVCRT__FPCLASS_SNAN
| MSVCRT__FPCLASS_QNAN
)) && !isinf(num
))
2392 *MSVCRT__errno() = MSVCRT_ERANGE
;
2396 FIXME("not implemented\n");
2401 /*********************************************************************
2402 * nexttowardf (MSVCR120.@)
2404 float CDECL
MSVCRT_nexttowardf(float num
, double next
)
2406 #ifdef HAVE_NEXTTOWARDF
2407 float ret
= nexttowardf(num
, next
);
2408 if (!(MSVCRT__fpclass(ret
) & (MSVCRT__FPCLASS_PN
| MSVCRT__FPCLASS_NN
2409 | MSVCRT__FPCLASS_SNAN
| MSVCRT__FPCLASS_QNAN
)) && !isinf(num
))
2411 *MSVCRT__errno() = MSVCRT_ERANGE
;
2415 FIXME("not implemented\n");
2420 #endif /* _MSVCR_VER>=120 */
2422 /*********************************************************************
2423 * _nextafter (MSVCRT.@)
2425 double CDECL
MSVCRT__nextafter(double num
, double next
)
2428 if (!isfinite(num
) || !isfinite(next
)) *MSVCRT__errno() = MSVCRT_EDOM
;
2429 retval
= nextafter(num
,next
);
2433 /*********************************************************************
2436 char * CDECL
MSVCRT__ecvt( double number
, int ndigits
, int *decpt
, int *sign
)
2439 thread_data_t
*data
= msvcrt_get_thread_data();
2440 /* FIXME: check better for overflow (native supports over 300 chars) */
2441 ndigits
= min( ndigits
, 80 - 7); /* 7 : space for dec point, 1 for "e",
2442 * 4 for exponent and one for
2443 * terminating '\0' */
2444 if (!data
->efcvt_buffer
)
2445 data
->efcvt_buffer
= MSVCRT_malloc( 80 ); /* ought to be enough */
2452 /* handle cases with zero ndigits or less */
2454 if( prec
< 1) prec
= 2;
2455 len
= MSVCRT__snprintf(data
->efcvt_buffer
, 80, "%.*le", prec
- 1, number
);
2456 /* take the decimal "point away */
2458 memmove( data
->efcvt_buffer
+ 1, data
->efcvt_buffer
+ 2, len
- 1 );
2459 /* take the exponential "e" out */
2460 data
->efcvt_buffer
[ prec
] = '\0';
2461 /* read the exponent */
2462 sscanf( data
->efcvt_buffer
+ prec
+ 1, "%d", decpt
);
2464 /* adjust for some border cases */
2465 if( data
->efcvt_buffer
[0] == '0')/* value is zero */
2467 /* handle cases with zero ndigits or less */
2469 if( data
->efcvt_buffer
[ 0] >= '5')
2471 data
->efcvt_buffer
[ 0] = '\0';
2473 TRACE("out=\"%s\"\n",data
->efcvt_buffer
);
2474 return data
->efcvt_buffer
;
2477 /*********************************************************************
2478 * _ecvt_s (MSVCRT.@)
2480 int CDECL
MSVCRT__ecvt_s( char *buffer
, MSVCRT_size_t length
, double number
, int ndigits
, int *decpt
, int *sign
)
2484 const char infret
[] = "1#INF";
2486 if (!MSVCRT_CHECK_PMT(buffer
!= NULL
)) return MSVCRT_EINVAL
;
2487 if (!MSVCRT_CHECK_PMT(decpt
!= NULL
)) return MSVCRT_EINVAL
;
2488 if (!MSVCRT_CHECK_PMT(sign
!= NULL
)) return MSVCRT_EINVAL
;
2489 if (!MSVCRT_CHECK_PMT_ERR( length
> 2, MSVCRT_ERANGE
)) return MSVCRT_ERANGE
;
2490 if (!MSVCRT_CHECK_PMT_ERR(ndigits
< (int)length
- 1, MSVCRT_ERANGE
)) return MSVCRT_ERANGE
;
2492 /* special case - inf */
2493 if(number
== HUGE_VAL
|| number
== -HUGE_VAL
)
2495 memset(buffer
, '0', ndigits
);
2496 memcpy(buffer
, infret
, min(ndigits
, sizeof(infret
) - 1 ) );
2497 buffer
[ndigits
] = '\0';
2499 if(number
== -HUGE_VAL
)
2505 /* handle cases with zero ndigits or less */
2507 if( prec
< 1) prec
= 2;
2508 result
= MSVCRT_malloc(prec
+ 7);
2515 len
= MSVCRT__snprintf(result
, prec
+ 7, "%.*le", prec
- 1, number
);
2516 /* take the decimal "point away */
2518 memmove( result
+ 1, result
+ 2, len
- 1 );
2519 /* take the exponential "e" out */
2520 result
[ prec
] = '\0';
2521 /* read the exponent */
2522 sscanf( result
+ prec
+ 1, "%d", decpt
);
2524 /* adjust for some border cases */
2525 if( result
[0] == '0')/* value is zero */
2527 /* handle cases with zero ndigits or less */
2529 if( result
[ 0] >= '5')
2533 memcpy( buffer
, result
, max(ndigits
+ 1, 1) );
2534 MSVCRT_free( result
);
2538 /***********************************************************************
2541 char * CDECL
MSVCRT__fcvt( double number
, int ndigits
, int *decpt
, int *sign
)
2543 thread_data_t
*data
= msvcrt_get_thread_data();
2544 int stop
, dec1
, dec2
;
2545 char *ptr1
, *ptr2
, *first
;
2546 char buf
[80]; /* ought to be enough */
2547 char decimal_separator
= get_locinfo()->lconv
->decimal_point
[0];
2549 if (!data
->efcvt_buffer
)
2550 data
->efcvt_buffer
= MSVCRT_malloc( 80 ); /* ought to be enough */
2558 stop
= MSVCRT__snprintf(buf
, 80, "%.*f", ndigits
< 0 ? 0 : ndigits
, number
);
2560 ptr2
= data
->efcvt_buffer
;
2565 /* For numbers below the requested resolution, work out where
2566 the decimal point will be rather than finding it in the string */
2567 if (number
< 1.0 && number
> 0.0) {
2568 dec2
= log10(number
+ 1e-10);
2569 if (-dec2
<= ndigits
) dec2
= 0;
2572 /* If requested digits is zero or less, we will need to truncate
2573 * the returned string */
2578 while (*ptr1
== '0') ptr1
++; /* Skip leading zeroes */
2579 while (*ptr1
!= '\0' && *ptr1
!= decimal_separator
) {
2580 if (!first
) first
= ptr2
;
2581 if ((ptr1
- buf
) < stop
) {
2592 while (*ptr1
== '0') { /* Process leading zeroes */
2597 while (*ptr1
!= '\0') {
2598 if (!first
) first
= ptr2
;
2605 /* We never found a non-zero digit, then our number is either
2606 * smaller than the requested precision, or 0.0 */
2611 first
= data
->efcvt_buffer
;
2616 *decpt
= dec2
? dec2
: dec1
;
2620 /***********************************************************************
2621 * _fcvt_s (MSVCRT.@)
2623 int CDECL
MSVCRT__fcvt_s(char* outbuffer
, MSVCRT_size_t size
, double number
, int ndigits
, int *decpt
, int *sign
)
2625 int stop
, dec1
, dec2
;
2626 char *ptr1
, *ptr2
, *first
;
2627 char buf
[80]; /* ought to be enough */
2628 char decimal_separator
= get_locinfo()->lconv
->decimal_point
[0];
2630 if (!outbuffer
|| !decpt
|| !sign
|| size
== 0)
2632 *MSVCRT__errno() = MSVCRT_EINVAL
;
2633 return MSVCRT_EINVAL
;
2642 stop
= MSVCRT__snprintf(buf
, 80, "%.*f", ndigits
< 0 ? 0 : ndigits
, number
);
2649 /* For numbers below the requested resolution, work out where
2650 the decimal point will be rather than finding it in the string */
2651 if (number
< 1.0 && number
> 0.0) {
2652 dec2
= log10(number
+ 1e-10);
2653 if (-dec2
<= ndigits
) dec2
= 0;
2656 /* If requested digits is zero or less, we will need to truncate
2657 * the returned string */
2662 while (*ptr1
== '0') ptr1
++; /* Skip leading zeroes */
2663 while (*ptr1
!= '\0' && *ptr1
!= decimal_separator
) {
2664 if (!first
) first
= ptr2
;
2665 if ((ptr1
- buf
) < stop
) {
2679 while (*ptr1
== '0') { /* Process leading zeroes */
2680 if (number
== 0.0 && size
> 1) {
2688 while (*ptr1
!= '\0') {
2689 if (!first
) first
= ptr2
;
2699 /* We never found a non-zero digit, then our number is either
2700 * smaller than the requested precision, or 0.0 */
2701 if (!first
&& (number
<= 0.0))
2704 *decpt
= dec2
? dec2
: dec1
;
2708 /***********************************************************************
2711 char * CDECL
MSVCRT__gcvt( double number
, int ndigit
, char *buff
)
2714 *MSVCRT__errno() = MSVCRT_EINVAL
;
2719 *MSVCRT__errno() = MSVCRT_ERANGE
;
2723 MSVCRT_sprintf(buff
, "%.*g", ndigit
, number
);
2727 /***********************************************************************
2728 * _gcvt_s (MSVCRT.@)
2730 int CDECL
MSVCRT__gcvt_s(char *buff
, MSVCRT_size_t size
, double number
, int digits
)
2735 *MSVCRT__errno() = MSVCRT_EINVAL
;
2736 return MSVCRT_EINVAL
;
2739 if( digits
<0 || digits
>=size
) {
2743 *MSVCRT__errno() = MSVCRT_ERANGE
;
2744 return MSVCRT_ERANGE
;
2747 len
= MSVCRT__scprintf("%.*g", digits
, number
);
2750 *MSVCRT__errno() = MSVCRT_ERANGE
;
2751 return MSVCRT_ERANGE
;
2754 MSVCRT_sprintf(buff
, "%.*g", digits
, number
);
2758 #include <stdlib.h> /* div_t, ldiv_t */
2760 /*********************************************************************
2763 * [i386] Windows binary compatible - returns the struct in eax/edx.
2766 unsigned __int64 CDECL
MSVCRT_div(int num
, int denom
)
2770 unsigned __int64 uint64
;
2773 ret
.div
.quot
= num
/ denom
;
2774 ret
.div
.rem
= num
% denom
;
2778 /*********************************************************************
2781 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
2783 MSVCRT_div_t CDECL
MSVCRT_div(int num
, int denom
)
2787 ret
.quot
= num
/ denom
;
2788 ret
.rem
= num
% denom
;
2791 #endif /* ifdef __i386__ */
2794 /*********************************************************************
2797 * [i386] Windows binary compatible - returns the struct in eax/edx.
2800 unsigned __int64 CDECL
MSVCRT_ldiv(MSVCRT_long num
, MSVCRT_long denom
)
2804 unsigned __int64 uint64
;
2807 ret
.ldiv
.quot
= num
/ denom
;
2808 ret
.ldiv
.rem
= num
% denom
;
2812 /*********************************************************************
2815 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
2817 MSVCRT_ldiv_t CDECL
MSVCRT_ldiv(MSVCRT_long num
, MSVCRT_long denom
)
2821 ret
.quot
= num
/ denom
;
2822 ret
.rem
= num
% denom
;
2825 #endif /* ifdef __i386__ */
2828 /*********************************************************************
2829 * lldiv (MSVCR100.@)
2831 MSVCRT_lldiv_t CDECL
MSVCRT_lldiv(MSVCRT_longlong num
, MSVCRT_longlong denom
)
2835 ret
.quot
= num
/ denom
;
2836 ret
.rem
= num
% denom
;
2844 /*********************************************************************
2845 * _adjust_fdiv (MSVCRT.@)
2846 * Used by the MSVC compiler to work around the Pentium FDIV bug.
2848 int MSVCRT__adjust_fdiv
= 0;
2850 /***********************************************************************
2851 * _adj_fdiv_m16i (MSVCRT.@)
2854 * I _think_ this function is intended to work around the Pentium
2857 void __stdcall
_adj_fdiv_m16i( short arg
)
2859 TRACE("(): stub\n");
2862 /***********************************************************************
2863 * _adj_fdiv_m32 (MSVCRT.@)
2866 * I _think_ this function is intended to work around the Pentium
2869 void __stdcall
_adj_fdiv_m32( unsigned int arg
)
2871 TRACE("(): stub\n");
2874 /***********************************************************************
2875 * _adj_fdiv_m32i (MSVCRT.@)
2878 * I _think_ this function is intended to work around the Pentium
2881 void __stdcall
_adj_fdiv_m32i( int arg
)
2883 TRACE("(): stub\n");
2886 /***********************************************************************
2887 * _adj_fdiv_m64 (MSVCRT.@)
2890 * I _think_ this function is intended to work around the Pentium
2893 void __stdcall
_adj_fdiv_m64( unsigned __int64 arg
)
2895 TRACE("(): stub\n");
2898 /***********************************************************************
2899 * _adj_fdiv_r (MSVCRT.@)
2901 * This function is likely to have the wrong number of arguments.
2904 * I _think_ this function is intended to work around the Pentium
2907 void _adj_fdiv_r(void)
2909 TRACE("(): stub\n");
2912 /***********************************************************************
2913 * _adj_fdivr_m16i (MSVCRT.@)
2916 * I _think_ this function is intended to work around the Pentium
2919 void __stdcall
_adj_fdivr_m16i( short arg
)
2921 TRACE("(): stub\n");
2924 /***********************************************************************
2925 * _adj_fdivr_m32 (MSVCRT.@)
2928 * I _think_ this function is intended to work around the Pentium
2931 void __stdcall
_adj_fdivr_m32( unsigned int arg
)
2933 TRACE("(): stub\n");
2936 /***********************************************************************
2937 * _adj_fdivr_m32i (MSVCRT.@)
2940 * I _think_ this function is intended to work around the Pentium
2943 void __stdcall
_adj_fdivr_m32i( int arg
)
2945 TRACE("(): stub\n");
2948 /***********************************************************************
2949 * _adj_fdivr_m64 (MSVCRT.@)
2952 * I _think_ this function is intended to work around the Pentium
2955 void __stdcall
_adj_fdivr_m64( unsigned __int64 arg
)
2957 TRACE("(): stub\n");
2960 /***********************************************************************
2961 * _adj_fpatan (MSVCRT.@)
2963 * This function is likely to have the wrong number of arguments.
2966 * I _think_ this function is intended to work around the Pentium
2969 void _adj_fpatan(void)
2971 TRACE("(): stub\n");
2974 /***********************************************************************
2975 * _adj_fprem (MSVCRT.@)
2977 * This function is likely to have the wrong number of arguments.
2980 * I _think_ this function is intended to work around the Pentium
2983 void _adj_fprem(void)
2985 TRACE("(): stub\n");
2988 /***********************************************************************
2989 * _adj_fprem1 (MSVCRT.@)
2991 * This function is likely to have the wrong number of arguments.
2994 * I _think_ this function is intended to work around the Pentium
2997 void _adj_fprem1(void)
2999 TRACE("(): stub\n");
3002 /***********************************************************************
3003 * _adj_fptan (MSVCRT.@)
3005 * This function is likely to have the wrong number of arguments.
3008 * I _think_ this function is intended to work around the Pentium
3011 void _adj_fptan(void)
3013 TRACE("(): stub\n");
3016 /***********************************************************************
3017 * _safe_fdiv (MSVCRT.@)
3019 * This function is likely to have the wrong number of arguments.
3022 * I _think_ this function is intended to work around the Pentium
3025 void _safe_fdiv(void)
3027 TRACE("(): stub\n");
3030 /***********************************************************************
3031 * _safe_fdivr (MSVCRT.@)
3033 * This function is likely to have the wrong number of arguments.
3036 * I _think_ this function is intended to work around the Pentium
3039 void _safe_fdivr(void)
3041 TRACE("(): stub\n");
3044 /***********************************************************************
3045 * _safe_fprem (MSVCRT.@)
3047 * This function is likely to have the wrong number of arguments.
3050 * I _think_ this function is intended to work around the Pentium
3053 void _safe_fprem(void)
3055 TRACE("(): stub\n");
3058 /***********************************************************************
3059 * _safe_fprem1 (MSVCRT.@)
3062 * This function is likely to have the wrong number of arguments.
3065 * I _think_ this function is intended to work around the Pentium
3068 void _safe_fprem1(void)
3070 TRACE("(): stub\n");
3073 /***********************************************************************
3074 * __libm_sse2_acos (MSVCRT.@)
3076 void __cdecl
MSVCRT___libm_sse2_acos(void)
3079 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
3081 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
3084 /***********************************************************************
3085 * __libm_sse2_acosf (MSVCRT.@)
3087 void __cdecl
MSVCRT___libm_sse2_acosf(void)
3090 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
3092 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
3095 /***********************************************************************
3096 * __libm_sse2_asin (MSVCRT.@)
3098 void __cdecl
MSVCRT___libm_sse2_asin(void)
3101 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
3103 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
3106 /***********************************************************************
3107 * __libm_sse2_asinf (MSVCRT.@)
3109 void __cdecl
MSVCRT___libm_sse2_asinf(void)
3112 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
3114 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
3117 /***********************************************************************
3118 * __libm_sse2_atan (MSVCRT.@)
3120 void __cdecl
MSVCRT___libm_sse2_atan(void)
3123 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
3125 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
3128 /***********************************************************************
3129 * __libm_sse2_atan2 (MSVCRT.@)
3131 void __cdecl
MSVCRT___libm_sse2_atan2(void)
3134 __asm__
__volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1
), "=m" (d2
) );
3135 d1
= atan2( d1
, d2
);
3136 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d1
) );
3139 /***********************************************************************
3140 * __libm_sse2_atanf (MSVCRT.@)
3142 void __cdecl
MSVCRT___libm_sse2_atanf(void)
3145 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
3147 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
3150 /***********************************************************************
3151 * __libm_sse2_cos (MSVCRT.@)
3153 void __cdecl
MSVCRT___libm_sse2_cos(void)
3156 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
3158 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
3161 /***********************************************************************
3162 * __libm_sse2_cosf (MSVCRT.@)
3164 void __cdecl
MSVCRT___libm_sse2_cosf(void)
3167 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
3169 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
3172 /***********************************************************************
3173 * __libm_sse2_exp (MSVCRT.@)
3175 void __cdecl
MSVCRT___libm_sse2_exp(void)
3178 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
3180 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
3183 /***********************************************************************
3184 * __libm_sse2_expf (MSVCRT.@)
3186 void __cdecl
MSVCRT___libm_sse2_expf(void)
3189 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
3191 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
3194 /***********************************************************************
3195 * __libm_sse2_log (MSVCRT.@)
3197 void __cdecl
MSVCRT___libm_sse2_log(void)
3200 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
3202 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
3205 /***********************************************************************
3206 * __libm_sse2_log10 (MSVCRT.@)
3208 void __cdecl
MSVCRT___libm_sse2_log10(void)
3211 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
3213 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
3216 /***********************************************************************
3217 * __libm_sse2_log10f (MSVCRT.@)
3219 void __cdecl
MSVCRT___libm_sse2_log10f(void)
3222 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
3224 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
3227 /***********************************************************************
3228 * __libm_sse2_logf (MSVCRT.@)
3230 void __cdecl
MSVCRT___libm_sse2_logf(void)
3233 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
3235 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
3238 /***********************************************************************
3239 * __libm_sse2_pow (MSVCRT.@)
3241 void __cdecl
MSVCRT___libm_sse2_pow(void)
3244 __asm__
__volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1
), "=m" (d2
) );
3246 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d1
) );
3249 /***********************************************************************
3250 * __libm_sse2_powf (MSVCRT.@)
3252 void __cdecl
MSVCRT___libm_sse2_powf(void)
3255 __asm__
__volatile__( "movd %%xmm0,%0; movd %%xmm1,%1" : "=g" (f1
), "=g" (f2
) );
3256 f1
= powf( f1
, f2
);
3257 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f1
) );
3260 /***********************************************************************
3261 * __libm_sse2_sin (MSVCRT.@)
3263 void __cdecl
MSVCRT___libm_sse2_sin(void)
3266 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
3268 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
3271 /***********************************************************************
3272 * __libm_sse2_sinf (MSVCRT.@)
3274 void __cdecl
MSVCRT___libm_sse2_sinf(void)
3277 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
3279 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
3282 /***********************************************************************
3283 * __libm_sse2_tan (MSVCRT.@)
3285 void __cdecl
MSVCRT___libm_sse2_tan(void)
3288 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
3290 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
3293 /***********************************************************************
3294 * __libm_sse2_tanf (MSVCRT.@)
3296 void __cdecl
MSVCRT___libm_sse2_tanf(void)
3299 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
3301 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
3304 /***********************************************************************
3305 * __libm_sse2_sqrt_precise (MSVCR110.@)
3307 void __cdecl
MSVCRT___libm_sse2_sqrt_precise(void)
3310 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
3312 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
3315 #endif /* __i386__ */
3317 /*********************************************************************
3320 double CDECL
MSVCR120_cbrt(double x
)
3325 return x
< 0 ? -pow(-x
, 1.0 / 3.0) : pow(x
, 1.0 / 3.0);
3329 /*********************************************************************
3330 * cbrtf (MSVCR120.@)
3332 float CDECL
MSVCR120_cbrtf(float x
)
3337 return MSVCR120_cbrt(x
);
3341 /*********************************************************************
3342 * cbrtl (MSVCR120.@)
3344 LDOUBLE CDECL
MSVCR120_cbrtl(LDOUBLE x
)
3346 return MSVCR120_cbrt(x
);
3349 /*********************************************************************
3352 double CDECL
MSVCR120_exp2(double x
)
3355 double ret
= exp2(x
);
3357 double ret
= pow(2, x
);
3359 if (isfinite(x
) && !isfinite(ret
)) *MSVCRT__errno() = MSVCRT_ERANGE
;
3363 /*********************************************************************
3364 * exp2f (MSVCR120.@)
3366 float CDECL
MSVCR120_exp2f(float x
)
3369 float ret
= exp2f(x
);
3370 if (isfinite(x
) && !isfinite(ret
)) *MSVCRT__errno() = MSVCRT_ERANGE
;
3373 return MSVCR120_exp2(x
);
3377 /*********************************************************************
3378 * exp2l (MSVCR120.@)
3380 LDOUBLE CDECL
MSVCR120_exp2l(LDOUBLE x
)
3382 return MSVCR120_exp2(x
);
3385 /*********************************************************************
3386 * expm1 (MSVCR120.@)
3388 double CDECL
MSVCR120_expm1(double x
)
3391 double ret
= expm1(x
);
3393 double ret
= exp(x
) - 1;
3395 if (isfinite(x
) && !isfinite(ret
)) *MSVCRT__errno() = MSVCRT_ERANGE
;
3399 /*********************************************************************
3400 * expm1f (MSVCR120.@)
3402 float CDECL
MSVCR120_expm1f(float x
)
3405 float ret
= expm1f(x
);
3407 float ret
= exp(x
) - 1;
3409 if (isfinite(x
) && !isfinite(ret
)) *MSVCRT__errno() = MSVCRT_ERANGE
;
3413 /*********************************************************************
3414 * expm1l (MSVCR120.@)
3416 LDOUBLE CDECL
MSVCR120_expm1l(LDOUBLE x
)
3418 return MSVCR120_expm1(x
);
3421 /*********************************************************************
3422 * log1p (MSVCR120.@)
3424 double CDECL
MSVCR120_log1p(double x
)
3426 if (x
< -1) *MSVCRT__errno() = MSVCRT_EDOM
;
3427 else if (x
== -1) *MSVCRT__errno() = MSVCRT_ERANGE
;
3435 /*********************************************************************
3436 * log1pf (MSVCR120.@)
3438 float CDECL
MSVCR120_log1pf(float x
)
3440 if (x
< -1) *MSVCRT__errno() = MSVCRT_EDOM
;
3441 else if (x
== -1) *MSVCRT__errno() = MSVCRT_ERANGE
;
3449 /*********************************************************************
3450 * log1pl (MSVCR120.@)
3452 LDOUBLE CDECL
MSVCR120_log1pl(LDOUBLE x
)
3454 return MSVCR120_log1p(x
);
3457 /*********************************************************************
3460 double CDECL
MSVCR120_log2(double x
)
3462 if (x
< 0) *MSVCRT__errno() = MSVCRT_EDOM
;
3463 else if (x
== 0) *MSVCRT__errno() = MSVCRT_ERANGE
;
3467 return log(x
) / log(2);
3471 /*********************************************************************
3472 * log2f (MSVCR120.@)
3474 float CDECL
MSVCR120_log2f(float x
)
3477 if (x
< 0) *MSVCRT__errno() = MSVCRT_EDOM
;
3478 else if (x
== 0) *MSVCRT__errno() = MSVCRT_ERANGE
;
3481 return MSVCR120_log2(x
);
3485 /*********************************************************************
3486 * log2l (MSVCR120.@)
3488 LDOUBLE CDECL
MSVCR120_log2l(LDOUBLE x
)
3490 return MSVCR120_log2(x
);
3493 /*********************************************************************
3496 double CDECL
MSVCR120_rint(double x
)
3501 /*********************************************************************
3502 * rintf (MSVCR120.@)
3504 float CDECL
MSVCR120_rintf(float x
)
3509 /*********************************************************************
3510 * rintl (MSVCR120.@)
3512 LDOUBLE CDECL
MSVCR120_rintl(LDOUBLE x
)
3514 return MSVCR120_rint(x
);
3517 /*********************************************************************
3518 * lrint (MSVCR120.@)
3520 MSVCRT_long CDECL
MSVCR120_lrint(double x
)
3525 /*********************************************************************
3526 * lrintf (MSVCR120.@)
3528 MSVCRT_long CDECL
MSVCR120_lrintf(float x
)
3533 /*********************************************************************
3534 * lrintl (MSVCR120.@)
3536 MSVCRT_long CDECL
MSVCR120_lrintl(LDOUBLE x
)
3538 return MSVCR120_lrint(x
);
3541 /*********************************************************************
3542 * llrint (MSVCR120.@)
3544 MSVCRT_longlong CDECL
MSVCR120_llrint(double x
)
3549 /*********************************************************************
3550 * llrintf (MSVCR120.@)
3552 MSVCRT_longlong CDECL
MSVCR120_llrintf(float x
)
3557 /*********************************************************************
3558 * rintl (MSVCR120.@)
3560 MSVCRT_longlong CDECL
MSVCR120_llrintl(LDOUBLE x
)
3562 return MSVCR120_llrint(x
);
3567 /*********************************************************************
3568 * round (MSVCR120.@)
3570 double CDECL
MSVCR120_round(double x
)
3575 return MSVCR120_rint(x
);
3579 /*********************************************************************
3580 * roundf (MSVCR120.@)
3582 float CDECL
MSVCR120_roundf(float x
)
3587 return MSVCR120_round(x
);
3591 /*********************************************************************
3592 * roundl (MSVCR120.@)
3594 LDOUBLE CDECL
MSVCR120_roundl(LDOUBLE x
)
3596 return MSVCR120_round(x
);
3599 /*********************************************************************
3600 * lround (MSVCR120.@)
3602 MSVCRT_long CDECL
MSVCR120_lround(double x
)
3607 return MSVCR120_round(x
);
3611 /*********************************************************************
3612 * lroundf (MSVCR120.@)
3614 MSVCRT_long CDECL
MSVCR120_lroundf(float x
)
3619 return MSVCR120_lround(x
);
3623 /*********************************************************************
3624 * lroundl (MSVCR120.@)
3626 MSVCRT_long CDECL
MSVCR120_lroundl(LDOUBLE x
)
3628 return MSVCR120_lround(x
);
3631 /*********************************************************************
3632 * llround (MSVCR120.@)
3634 MSVCRT_longlong CDECL
MSVCR120_llround(double x
)
3639 return MSVCR120_round(x
);
3643 /*********************************************************************
3644 * llroundf (MSVCR120.@)
3646 MSVCRT_longlong CDECL
MSVCR120_llroundf(float x
)
3648 #ifdef HAVE_LLROUNDF
3651 return MSVCR120_llround(x
);
3655 /*********************************************************************
3656 * roundl (MSVCR120.@)
3658 MSVCRT_longlong CDECL
MSVCR120_llroundl(LDOUBLE x
)
3660 return MSVCR120_llround(x
);
3663 /*********************************************************************
3664 * trunc (MSVCR120.@)
3666 double CDECL
MSVCR120_trunc(double x
)
3671 return (x
> 0) ? floor(x
) : ceil(x
);
3675 /*********************************************************************
3676 * truncf (MSVCR120.@)
3678 float CDECL
MSVCR120_truncf(float x
)
3683 return MSVCR120_trunc(x
);
3687 /*********************************************************************
3688 * truncl (MSVCR120.@)
3690 LDOUBLE CDECL
MSVCR120_truncl(LDOUBLE x
)
3692 return MSVCR120_trunc(x
);
3695 /*********************************************************************
3696 * _dclass (MSVCR120.@)
3698 * Copied from musl: src/math/__fpclassify.c
3700 short CDECL
MSVCR120__dclass(double x
)
3702 union { double f
; UINT64 i
; } u
= { x
};
3703 int e
= u
.i
>> 52 & 0x7ff;
3705 if (!e
) return u
.i
<< 1 ? MSVCRT_FP_SUBNORMAL
: MSVCRT_FP_ZERO
;
3706 if (e
== 0x7ff) return (u
.i
<< 12) ? MSVCRT_FP_NAN
: MSVCRT_FP_INFINITE
;
3707 return MSVCRT_FP_NORMAL
;
3710 /*********************************************************************
3711 * _fdclass (MSVCR120.@)
3713 * Copied from musl: src/math/__fpclassifyf.c
3715 short CDECL
MSVCR120__fdclass(float x
)
3717 union { float f
; UINT32 i
; } u
= { x
};
3718 int e
= u
.i
>> 23 & 0xff;
3720 if (!e
) return u
.i
<< 1 ? MSVCRT_FP_SUBNORMAL
: MSVCRT_FP_ZERO
;
3721 if (e
== 0xff) return u
.i
<< 9 ? MSVCRT_FP_NAN
: MSVCRT_FP_INFINITE
;
3722 return MSVCRT_FP_NORMAL
;
3725 /*********************************************************************
3726 * _ldclass (MSVCR120.@)
3728 short CDECL
MSVCR120__ldclass(LDOUBLE x
)
3730 return MSVCR120__dclass(x
);
3733 /*********************************************************************
3734 * _dtest (MSVCR120.@)
3736 short CDECL
MSVCR120__dtest(double *x
)
3738 return MSVCR120__dclass(*x
);
3741 /*********************************************************************
3742 * _fdtest (MSVCR120.@)
3744 short CDECL
MSVCR120__fdtest(float *x
)
3746 return MSVCR120__fdclass(*x
);
3749 /*********************************************************************
3750 * _ldtest (MSVCR120.@)
3752 short CDECL
MSVCR120__ldtest(LDOUBLE
*x
)
3754 return MSVCR120__dclass(*x
);
3757 /*********************************************************************
3760 double CDECL
MSVCR120_erf(double x
)
3765 /* Abramowitz and Stegun approximation, maximum error: 1.5*10^-7 */
3767 int sign
= signbit(x
);
3770 t
= 1 / (1 + 0.3275911 * x
);
3771 y
= ((((1.061405429*t
- 1.453152027)*t
+ 1.421413741)*t
- 0.284496736)*t
+ 0.254829592)*t
;
3772 y
= 1.0 - y
*exp(-x
*x
);
3773 return sign
? -y
: y
;
3777 /*********************************************************************
3780 float CDECL
MSVCR120_erff(float x
)
3785 return MSVCR120_erf(x
);
3789 /*********************************************************************
3792 LDOUBLE CDECL
MSVCR120_erfl(LDOUBLE x
)
3794 return MSVCR120_erf(x
);
3797 /*********************************************************************
3800 double CDECL
MSVCR120_erfc(double x
)
3805 return 1 - MSVCR120_erf(x
);
3809 /*********************************************************************
3810 * erfcf (MSVCR120.@)
3812 float CDECL
MSVCR120_erfcf(float x
)
3817 return MSVCR120_erfc(x
);
3821 /*********************************************************************
3822 * erfcl (MSVCR120.@)
3824 LDOUBLE CDECL
MSVCR120_erfcl(LDOUBLE x
)
3826 return MSVCR120_erfc(x
);
3829 /*********************************************************************
3830 * fmaxf (MSVCR120.@)
3832 float CDECL
MSVCR120_fmaxf(float x
, float y
)
3839 return signbit(x
) ? y
: x
;
3843 /*********************************************************************
3846 double CDECL
MSVCR120_fmax(double x
, double y
)
3853 return signbit(x
) ? y
: x
;
3857 /*********************************************************************
3858 * fdimf (MSVCR120.@)
3860 float CDECL
MSVCR120_fdimf(float x
, float y
)
3866 return x
>y
? x
-y
: 0;
3869 /*********************************************************************
3872 double CDECL
MSVCR120_fdim(double x
, double y
)
3878 return x
>y
? x
-y
: 0;
3881 /*********************************************************************
3882 * _fdsign (MSVCR120.@)
3884 int CDECL
MSVCR120__fdsign(float x
)
3886 union { float f
; UINT32 i
; } u
= { x
};
3887 return (u
.i
>> 16) & 0x8000;
3890 /*********************************************************************
3891 * _dsign (MSVCR120.@)
3893 int CDECL
MSVCR120__dsign(double x
)
3895 union { double f
; UINT64 i
; } u
= { x
};
3896 return (u
.i
>> 48) & 0x8000;
3900 /*********************************************************************
3901 * _dpcomp (MSVCR120.@)
3903 int CDECL
MSVCR120__dpcomp(double x
, double y
)
3905 if(isnan(x
) || isnan(y
))
3908 if(x
== y
) return 2;
3909 return x
< y
? 1 : 4;
3912 /*********************************************************************
3913 * _fdpcomp (MSVCR120.@)
3915 int CDECL
MSVCR120__fdpcomp(float x
, float y
)
3917 return MSVCR120__dpcomp(x
, y
);
3920 /*********************************************************************
3921 * fminf (MSVCR120.@)
3923 float CDECL
MSVCR120_fminf(float x
, float y
)
3930 return signbit(x
) ? x
: y
;
3934 /*********************************************************************
3937 double CDECL
MSVCR120_fmin(double x
, double y
)
3944 return signbit(x
) ? x
: y
;
3948 /*********************************************************************
3949 * asinh (MSVCR120.@)
3951 double CDECL
MSVCR120_asinh(double x
)
3956 if (!isfinite(x
*x
+1)) {
3957 if (x
> 0) return log(2) + log(x
);
3958 else return -log(2) - log(-x
);
3960 return log(x
+ sqrt(x
*x
+1));
3964 /*********************************************************************
3965 * asinhf (MSVCR120.@)
3967 float CDECL
MSVCR120_asinhf(float x
)
3972 return MSVCR120_asinh(x
);
3976 /*********************************************************************
3977 * asinhl (MSVCR120.@)
3979 LDOUBLE CDECL
MSVCR120_asinhl(LDOUBLE x
)
3981 return MSVCR120_asinh(x
);
3984 /*********************************************************************
3985 * acosh (MSVCR120.@)
3987 double CDECL
MSVCR120_acosh(double x
)
3989 if (x
< 1) *MSVCRT__errno() = MSVCRT_EDOM
;
3997 MSVCRT_fegetenv(&env
);
3998 env
.status
|= MSVCRT__SW_INVALID
;
3999 MSVCRT_fesetenv(&env
);
4002 if (!isfinite(x
*x
)) return log(2) + log(x
);
4003 return log(x
+ sqrt(x
*x
-1));
4007 /*********************************************************************
4008 * acoshf (MSVCR120.@)
4010 float CDECL
MSVCR120_acoshf(float x
)
4013 if (x
< 1) *MSVCRT__errno() = MSVCRT_EDOM
;
4017 return MSVCR120_acosh(x
);
4021 /*********************************************************************
4022 * acoshl (MSVCR120.@)
4024 LDOUBLE CDECL
MSVCR120_acoshl(LDOUBLE x
)
4026 return MSVCR120_acosh(x
);
4029 /*********************************************************************
4030 * atanh (MSVCR120.@)
4032 double CDECL
MSVCR120_atanh(double x
)
4036 if (x
> 1 || x
< -1) {
4039 *MSVCRT__errno() = MSVCRT_EDOM
;
4041 /* on Linux atanh returns -NAN in this case */
4042 MSVCRT_fegetenv(&env
);
4043 env
.status
|= MSVCRT__SW_INVALID
;
4044 MSVCRT_fesetenv(&env
);
4051 if (-1e-6 < x
&& x
< 1e-6) ret
= x
+ x
*x
*x
/3;
4052 else ret
= (log(1+x
) - log(1-x
)) / 2;
4055 if (!isfinite(ret
)) *MSVCRT__errno() = MSVCRT_ERANGE
;
4059 /*********************************************************************
4060 * atanhf (MSVCR120.@)
4062 float CDECL
MSVCR120_atanhf(float x
)
4067 if (x
> 1 || x
< -1) {
4070 *MSVCRT__errno() = MSVCRT_EDOM
;
4072 MSVCRT_fegetenv(&env
);
4073 env
.status
|= MSVCRT__SW_INVALID
;
4074 MSVCRT_fesetenv(&env
);
4080 if (!isfinite(ret
)) *MSVCRT__errno() = MSVCRT_ERANGE
;
4083 return MSVCR120_atanh(x
);
4087 /*********************************************************************
4088 * atanhl (MSVCR120.@)
4090 LDOUBLE CDECL
MSVCR120_atanhl(LDOUBLE x
)
4092 return MSVCR120_atanh(x
);
4095 #endif /* _MSVCR_VER>=120 */
4097 /*********************************************************************
4099 * scalbn (MSVCR120.@)
4100 * scalbln (MSVCR120.@)
4102 double CDECL
MSVCRT__scalb(double num
, MSVCRT_long power
)
4104 return MSVCRT_ldexp(num
, power
);
4107 /*********************************************************************
4108 * _scalbf (MSVCRT.@)
4109 * scalbnf (MSVCR120.@)
4110 * scalblnf (MSVCR120.@)
4112 float CDECL
MSVCRT__scalbf(float num
, MSVCRT_long power
)
4114 return MSVCRT_ldexp(num
, power
);
4119 /*********************************************************************
4120 * scalbnl (MSVCR120.@)
4121 * scalblnl (MSVCR120.@)
4123 LDOUBLE CDECL
MSVCR120_scalbnl(LDOUBLE num
, MSVCRT_long power
)
4125 return MSVCRT__scalb(num
, power
);
4128 /*********************************************************************
4129 * remainder (MSVCR120.@)
4131 double CDECL
MSVCR120_remainder(double x
, double y
)
4133 #ifdef HAVE_REMAINDER
4134 /* this matches 64-bit Windows. 32-bit Windows is slightly different */
4135 if(!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
4136 if(isnan(y
) || y
==0.0) *MSVCRT__errno() = MSVCRT_EDOM
;
4137 return remainder(x
, y
);
4139 FIXME( "not implemented\n" );
4144 /*********************************************************************
4145 * remainderf (MSVCR120.@)
4147 float CDECL
MSVCR120_remainderf(float x
, float y
)
4149 #ifdef HAVE_REMAINDERF
4150 /* this matches 64-bit Windows. 32-bit Windows is slightly different */
4151 if(!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
4152 if(isnan(y
) || y
==0.0f
) *MSVCRT__errno() = MSVCRT_EDOM
;
4153 return remainderf(x
, y
);
4155 FIXME( "not implemented\n" );
4160 /*********************************************************************
4161 * remainderl (MSVCR120.@)
4163 LDOUBLE CDECL
MSVCR120_remainderl(LDOUBLE x
, LDOUBLE y
)
4165 return MSVCR120_remainder(x
, y
);
4168 /*********************************************************************
4169 * remquo (MSVCR120.@)
4171 double CDECL
MSVCR120_remquo(double x
, double y
, int *quo
)
4174 if(!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
4175 if(isnan(y
) || y
==0.0) *MSVCRT__errno() = MSVCRT_EDOM
;
4176 return remquo(x
, y
, quo
);
4178 FIXME( "not implemented\n" );
4183 /*********************************************************************
4184 * remquof (MSVCR120.@)
4186 float CDECL
MSVCR120_remquof(float x
, float y
, int *quo
)
4189 if(!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
4190 if(isnan(y
) || y
==0.0f
) *MSVCRT__errno() = MSVCRT_EDOM
;
4191 return remquof(x
, y
, quo
);
4193 FIXME( "not implemented\n" );
4198 /*********************************************************************
4199 * remquol (MSVCR120.@)
4201 LDOUBLE CDECL
MSVCR120_remquol(LDOUBLE x
, LDOUBLE y
, int *quo
)
4203 return MSVCR120_remquo(x
, y
, quo
);
4206 /*********************************************************************
4207 * lgamma (MSVCR120.@)
4209 double CDECL
MSVCR120_lgamma(double x
)
4214 FIXME( "not implemented\n" );
4219 /*********************************************************************
4220 * lgammaf (MSVCR120.@)
4222 float CDECL
MSVCR120_lgammaf(float x
)
4227 FIXME( "not implemented\n" );
4232 /*********************************************************************
4233 * lgammal (MSVCR120.@)
4235 LDOUBLE CDECL
MSVCR120_lgammal(LDOUBLE x
)
4237 return MSVCR120_lgamma(x
);
4240 /*********************************************************************
4241 * tgamma (MSVCR120.@)
4243 double CDECL
MSVCR120_tgamma(double x
)
4246 if(x
==0.0) *MSVCRT__errno() = MSVCRT_ERANGE
;
4249 if (modf(x
, &integral
) == 0)
4250 *MSVCRT__errno() = MSVCRT_EDOM
;
4254 FIXME( "not implemented\n" );
4259 /*********************************************************************
4260 * tgammaf (MSVCR120.@)
4262 float CDECL
MSVCR120_tgammaf(float x
)
4265 if(x
==0.0f
) *MSVCRT__errno() = MSVCRT_ERANGE
;
4268 if (modff(x
, &integral
) == 0)
4269 *MSVCRT__errno() = MSVCRT_EDOM
;
4273 FIXME( "not implemented\n" );
4278 /*********************************************************************
4281 double CDECL
MSVCR120_nan(const char *tagp
)
4283 /* Windows ignores input (MSDN) */
4287 /*********************************************************************
4290 float CDECL
MSVCR120_nanf(const char *tagp
)
4295 /*********************************************************************
4296 * _except1 (MSVCR120.@)
4298 * - find meaning of ignored cw and operation bits
4301 double CDECL
_except1(DWORD fpe
, _FP_OPERATION_CODE op
, double arg
, double res
, DWORD cw
, void *unk
)
4303 ULONG_PTR exception_arg
;
4304 DWORD exception
= 0;
4309 TRACE("(%x %x %lf %lf %x %p)\n", fpe
, op
, arg
, res
, cw
, unk
);
4312 cw
= ((cw
>> 7) & 0x3f) | ((cw
>> 3) & 0xc00);
4314 operation
= op
<< 5;
4315 exception_arg
= (ULONG_PTR
)&operation
;
4317 MSVCRT_fegetenv(&env
);
4319 if (fpe
& 0x1) { /* overflow */
4320 if ((fpe
== 0x1 && (cw
& 0x8)) || (fpe
==0x11 && (cw
& 0x28))) {
4321 /* 32-bit version also sets SW_INEXACT here */
4322 env
.status
|= MSVCRT__SW_OVERFLOW
;
4323 if (fpe
& 0x10) env
.status
|= MSVCRT__SW_INEXACT
;
4324 res
= signbit(res
) ? -INFINITY
: INFINITY
;
4326 exception
= EXCEPTION_FLT_OVERFLOW
;
4328 } else if (fpe
& 0x2) { /* underflow */
4329 if ((fpe
== 0x2 && (cw
& 0x10)) || (fpe
==0x12 && (cw
& 0x30))) {
4330 env
.status
|= MSVCRT__SW_UNDERFLOW
;
4331 if (fpe
& 0x10) env
.status
|= MSVCRT__SW_INEXACT
;
4332 res
= signbit(res
) ? -0.0 : 0.0;
4334 exception
= EXCEPTION_FLT_UNDERFLOW
;
4336 } else if (fpe
& 0x4) { /* zerodivide */
4337 if ((fpe
== 0x4 && (cw
& 0x4)) || (fpe
==0x14 && (cw
& 0x24))) {
4338 env
.status
|= MSVCRT__SW_ZERODIVIDE
;
4339 if (fpe
& 0x10) env
.status
|= MSVCRT__SW_INEXACT
;
4341 exception
= EXCEPTION_FLT_DIVIDE_BY_ZERO
;
4343 } else if (fpe
& 0x8) { /* invalid */
4344 if (fpe
== 0x8 && (cw
& 0x1)) {
4345 env
.status
|= MSVCRT__SW_INVALID
;
4347 exception
= EXCEPTION_FLT_INVALID_OPERATION
;
4349 } else if (fpe
& 0x10) { /* inexact */
4350 if (fpe
== 0x10 && (cw
& 0x20)) {
4351 env
.status
|= MSVCRT__SW_INEXACT
;
4353 exception
= EXCEPTION_FLT_INEXACT_RESULT
;
4359 MSVCRT_fesetenv(&env
);
4361 RaiseException(exception
, 0, 1, &exception_arg
);
4363 if (cw
& 0x1) fpword
|= MSVCRT__EM_INVALID
;
4364 if (cw
& 0x2) fpword
|= MSVCRT__EM_DENORMAL
;
4365 if (cw
& 0x4) fpword
|= MSVCRT__EM_ZERODIVIDE
;
4366 if (cw
& 0x8) fpword
|= MSVCRT__EM_OVERFLOW
;
4367 if (cw
& 0x10) fpword
|= MSVCRT__EM_UNDERFLOW
;
4368 if (cw
& 0x20) fpword
|= MSVCRT__EM_INEXACT
;
4371 case 0xc00: fpword
|= MSVCRT__RC_UP
|MSVCRT__RC_DOWN
; break;
4372 case 0x800: fpword
|= MSVCRT__RC_UP
; break;
4373 case 0x400: fpword
|= MSVCRT__RC_DOWN
; break;
4377 case 0x0: fpword
|= MSVCRT__PC_24
; break;
4378 case 0x200: fpword
|= MSVCRT__PC_53
; break;
4379 case 0x300: fpword
|= MSVCRT__PC_64
; break;
4381 if (cw
& 0x1000) fpword
|= MSVCRT__IC_AFFINE
;
4382 _control87(fpword
, 0xffffffff);
4387 _Dcomplex
* CDECL
MSVCR120__Cbuild(_Dcomplex
*ret
, double r
, double i
)
4394 double CDECL
MSVCR120_creal(_Dcomplex z
)
4399 /*********************************************************************
4400 * ilogb (MSVCR120.@)
4402 * Copied from musl: src/math/ilogb.c
4404 int CDECL
MSVCR120_ilogb(double x
)
4406 union { double f
; UINT64 i
; } u
= { x
};
4407 int e
= u
.i
>> 52 & 0x7ff;
4412 if (u
.i
== 0) return MSVCRT_FP_ILOGB0
;
4414 for (e
= -0x3ff; u
.i
>> 63 == 0; e
--, u
.i
<<= 1);
4417 if (e
== 0x7ff) return u
.i
<< 12 ? MSVCRT_FP_ILOGBNAN
: MSVCRT_INT_MAX
;
4421 /*********************************************************************
4422 * ilogbf (MSVCR120.@)
4424 * Copied from musl: src/math/ilogbf.c
4426 int CDECL
MSVCR120_ilogbf(float x
)
4428 union { float f
; UINT32 i
; } u
= { x
};
4429 int e
= u
.i
>> 23 & 0xff;
4434 if (u
.i
== 0) return MSVCRT_FP_ILOGB0
;
4436 for (e
= -0x7f; u
.i
>> 31 == 0; e
--, u
.i
<<= 1);
4439 if (e
== 0xff) return u
.i
<< 9 ? MSVCRT_FP_ILOGBNAN
: MSVCRT_INT_MAX
;
4443 /*********************************************************************
4444 * ilogbl (MSVCR120.@)
4446 int CDECL
MSVCR120_ilogbl(LDOUBLE x
)
4448 return MSVCR120_ilogb(x
);
4451 #endif /* _MSVCR_VER>=120 */