d3d8/tests: Add a system memory miptree layout test.
[wine.git] / dlls / msvcrt / math.c
blobb9e0533865881ca11c3632e083ab27ae5e88252d
1 /*
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
20 #include "config.h"
21 #include "wine/port.h"
23 #include <stdio.h>
24 #define __USE_ISOC9X 1
25 #define __USE_ISOC99 1
26 #include <math.h>
27 #ifdef HAVE_IEEEFP_H
28 #include <ieeefp.h>
29 #endif
31 #include "msvcrt.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
37 #ifndef HAVE_FINITEF
38 #define finitef(x) isfinite(x)
39 #endif
41 #ifndef HAVE_ISNANF
42 #ifdef HAVE_ISNAN
43 #define isnanf(x) isnan(x)
44 #else
45 #define isnanf(x) 0
46 #endif
47 #endif
49 /* FIXME: Does not work with -NAN and -0. */
50 #ifndef signbit
51 #define signbit(x) ((x) < 0)
52 #endif
54 typedef int (CDECL *MSVCRT_matherr_func)(struct MSVCRT__exception *);
55 typedef double LDOUBLE; /* long double is just a double */
57 static MSVCRT_matherr_func MSVCRT_default_matherr_func = NULL;
59 static BOOL sse2_supported;
60 static BOOL sse2_enabled;
62 void msvcrt_init_math(void)
64 sse2_supported = sse2_enabled = IsProcessorFeaturePresent( PF_XMMI64_INSTRUCTIONS_AVAILABLE );
67 /*********************************************************************
68 * _set_SSE2_enable (MSVCRT.@)
70 int CDECL MSVCRT__set_SSE2_enable(int flag)
72 sse2_enabled = flag && sse2_supported;
73 return sse2_enabled;
76 #ifdef _WIN64
77 /*********************************************************************
78 * _set_FMA3_enable (MSVCR120.@)
80 int CDECL MSVCRT__set_FMA3_enable(int flag)
82 FIXME("(%x) stub\n", flag);
83 return 0;
85 #endif
87 #if defined(__x86_64__) || defined(__arm__) || _MSVCR_VER>=120
89 /*********************************************************************
90 * _chgsignf (MSVCRT.@)
92 float CDECL MSVCRT__chgsignf( float num )
94 /* FIXME: +-infinity,Nan not tested */
95 return -num;
98 /*********************************************************************
99 * _copysignf (MSVCRT.@)
101 float CDECL MSVCRT__copysignf( float num, float sign )
103 if (signbit(sign))
104 return signbit(num) ? num : -num;
105 return signbit(num) ? -num : num;
108 /*********************************************************************
109 * _nextafterf (MSVCRT.@)
111 float CDECL MSVCRT__nextafterf( float num, float next )
113 if (!finitef(num) || !finitef(next)) *MSVCRT__errno() = MSVCRT_EDOM;
114 return nextafterf( num, next );
117 #endif
118 #if defined(__x86_64__) || defined(__arm__)
120 /*********************************************************************
121 * _finitef (MSVCRT.@)
123 int CDECL MSVCRT__finitef( float num )
125 return finitef(num) != 0; /* See comment for _isnan() */
128 /*********************************************************************
129 * _isnanf (MSVCRT.@)
131 INT CDECL MSVCRT__isnanf( float num )
133 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
134 * Do the same, as the result may be used in calculations
136 return isnanf(num) != 0;
139 /*********************************************************************
140 * _logbf (MSVCRT.@)
142 float CDECL MSVCRT__logbf( float num )
144 if (!finitef(num)) *MSVCRT__errno() = MSVCRT_EDOM;
145 return logbf(num);
148 /*********************************************************************
149 * MSVCRT_acosf (MSVCRT.@)
151 float CDECL MSVCRT_acosf( float x )
153 if (x < -1.0 || x > 1.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
154 /* glibc implements acos() as the FPU equivalent of atan2(sqrt(1 - x ^ 2), x).
155 * asin() uses a similar construction. This is bad because as x gets nearer to
156 * 1 the error in the expression "1 - x^2" can get relatively large due to
157 * cancellation. The sqrt() makes things worse. A safer way to calculate
158 * acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */
159 return atan2f(sqrtf((1 - x) * (1 + x)), x);
162 /*********************************************************************
163 * MSVCRT_asinf (MSVCRT.@)
165 float CDECL MSVCRT_asinf( float x )
167 if (x < -1.0 || x > 1.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
168 return atan2f(x, sqrtf((1 - x) * (1 + x)));
171 /*********************************************************************
172 * MSVCRT_atanf (MSVCRT.@)
174 float CDECL MSVCRT_atanf( float x )
176 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
177 return atanf(x);
180 /*********************************************************************
181 * MSVCRT_atan2f (MSVCRT.@)
183 float CDECL MSVCRT_atan2f( float x, float y )
185 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
186 return atan2f(x,y);
189 /*********************************************************************
190 * MSVCRT_cosf (MSVCRT.@)
192 float CDECL MSVCRT_cosf( float x )
194 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
195 return cosf(x);
198 /*********************************************************************
199 * MSVCRT_coshf (MSVCRT.@)
201 float CDECL MSVCRT_coshf( float x )
203 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
204 return coshf(x);
207 /*********************************************************************
208 * MSVCRT_expf (MSVCRT.@)
210 float CDECL MSVCRT_expf( float x )
212 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
213 return expf(x);
216 /*********************************************************************
217 * MSVCRT_fmodf (MSVCRT.@)
219 float CDECL MSVCRT_fmodf( float x, float y )
221 if (!finitef(x) || !finitef(y)) *MSVCRT__errno() = MSVCRT_EDOM;
222 return fmodf(x,y);
225 /*********************************************************************
226 * MSVCRT_logf (MSVCRT.@)
228 float CDECL MSVCRT_logf( float x)
230 if (x < 0.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
231 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
232 return logf(x);
235 /*********************************************************************
236 * MSVCRT_log10f (MSVCRT.@)
238 float CDECL MSVCRT_log10f( float x )
240 if (x < 0.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
241 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
242 return log10f(x);
245 /*********************************************************************
246 * MSVCRT_powf (MSVCRT.@)
248 float CDECL MSVCRT_powf( float x, float y )
250 /* FIXME: If x < 0 and y is not integral, set EDOM */
251 float z = powf(x,y);
252 if (!finitef(z)) *MSVCRT__errno() = MSVCRT_EDOM;
253 return z;
256 /*********************************************************************
257 * MSVCRT_sinf (MSVCRT.@)
259 float CDECL MSVCRT_sinf( float x )
261 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
262 return sinf(x);
265 /*********************************************************************
266 * MSVCRT_sinhf (MSVCRT.@)
268 float CDECL MSVCRT_sinhf( float x )
270 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
271 return sinhf(x);
274 /*********************************************************************
275 * MSVCRT_sqrtf (MSVCRT.@)
277 float CDECL MSVCRT_sqrtf( float x )
279 if (x < 0.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
280 return sqrtf(x);
283 /*********************************************************************
284 * MSVCRT_tanf (MSVCRT.@)
286 float CDECL MSVCRT_tanf( float x )
288 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
289 return tanf(x);
292 /*********************************************************************
293 * MSVCRT_tanhf (MSVCRT.@)
295 float CDECL MSVCRT_tanhf( float x )
297 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
298 return tanhf(x);
301 /*********************************************************************
302 * ceilf (MSVCRT.@)
304 float CDECL MSVCRT_ceilf( float x )
306 return ceilf(x);
309 /*********************************************************************
310 * fabsf (MSVCRT.@)
312 float CDECL MSVCRT_fabsf( float x )
314 return fabsf(x);
317 /*********************************************************************
318 * floorf (MSVCRT.@)
320 float CDECL MSVCRT_floorf( float x )
322 return floorf(x);
325 /*********************************************************************
326 * frexpf (MSVCRT.@)
328 float CDECL MSVCRT_frexpf( float x, int *exp )
330 return frexpf( x, exp );
333 /*********************************************************************
334 * modff (MSVCRT.@)
336 float CDECL MSVCRT_modff( float x, float *iptr )
338 return modff( x, iptr );
341 #endif
343 /*********************************************************************
344 * MSVCRT_acos (MSVCRT.@)
346 double CDECL MSVCRT_acos( double x )
348 if (x < -1.0 || x > 1.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
349 /* glibc implements acos() as the FPU equivalent of atan2(sqrt(1 - x ^ 2), x).
350 * asin() uses a similar construction. This is bad because as x gets nearer to
351 * 1 the error in the expression "1 - x^2" can get relatively large due to
352 * cancellation. The sqrt() makes things worse. A safer way to calculate
353 * acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */
354 return atan2(sqrt((1 - x) * (1 + x)), x);
357 /*********************************************************************
358 * MSVCRT_asin (MSVCRT.@)
360 double CDECL MSVCRT_asin( double x )
362 if (x < -1.0 || x > 1.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
363 return atan2(x, sqrt((1 - x) * (1 + x)));
366 /*********************************************************************
367 * MSVCRT_atan (MSVCRT.@)
369 double CDECL MSVCRT_atan( double x )
371 if (isnan(x)) *MSVCRT__errno() = MSVCRT_EDOM;
372 return atan(x);
375 /*********************************************************************
376 * MSVCRT_atan2 (MSVCRT.@)
378 double CDECL MSVCRT_atan2( double x, double y )
380 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
381 return atan2(x,y);
384 /*********************************************************************
385 * MSVCRT_cos (MSVCRT.@)
387 double CDECL MSVCRT_cos( double x )
389 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
390 return cos(x);
393 /*********************************************************************
394 * MSVCRT_cosh (MSVCRT.@)
396 double CDECL MSVCRT_cosh( double x )
398 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
399 return cosh(x);
402 /*********************************************************************
403 * MSVCRT_exp (MSVCRT.@)
405 double CDECL MSVCRT_exp( double x )
407 if (isnan(x)) *MSVCRT__errno() = MSVCRT_EDOM;
408 return exp(x);
411 /*********************************************************************
412 * MSVCRT_fmod (MSVCRT.@)
414 double CDECL MSVCRT_fmod( double x, double y )
416 if (!isfinite(x) || !isfinite(y)) *MSVCRT__errno() = MSVCRT_EDOM;
417 return fmod(x,y);
420 /*********************************************************************
421 * MSVCRT_log (MSVCRT.@)
423 double CDECL MSVCRT_log( double x)
425 if (x < 0.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
426 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
427 return log(x);
430 /*********************************************************************
431 * MSVCRT_log10 (MSVCRT.@)
433 double CDECL MSVCRT_log10( double x )
435 if (x < 0.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
436 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
437 return log10(x);
440 /*********************************************************************
441 * MSVCRT_pow (MSVCRT.@)
443 double CDECL MSVCRT_pow( double x, double y )
445 /* FIXME: If x < 0 and y is not integral, set EDOM */
446 double z = pow(x,y);
447 if (!isfinite(z)) *MSVCRT__errno() = MSVCRT_EDOM;
448 return z;
451 /*********************************************************************
452 * MSVCRT_sin (MSVCRT.@)
454 double CDECL MSVCRT_sin( double x )
456 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
457 return sin(x);
460 /*********************************************************************
461 * MSVCRT_sinh (MSVCRT.@)
463 double CDECL MSVCRT_sinh( double x )
465 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
466 return sinh(x);
469 /*********************************************************************
470 * MSVCRT_sqrt (MSVCRT.@)
472 double CDECL MSVCRT_sqrt( double x )
474 if (x < 0.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
475 return sqrt(x);
478 /*********************************************************************
479 * MSVCRT_tan (MSVCRT.@)
481 double CDECL MSVCRT_tan( double x )
483 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
484 return tan(x);
487 /*********************************************************************
488 * MSVCRT_tanh (MSVCRT.@)
490 double CDECL MSVCRT_tanh( double x )
492 if (isnan(x)) *MSVCRT__errno() = MSVCRT_EDOM;
493 return tanh(x);
497 #if defined(__GNUC__) && defined(__i386__)
499 #define FPU_DOUBLE(var) double var; \
500 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
501 #define FPU_DOUBLES(var1,var2) double var1,var2; \
502 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
503 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
505 /*********************************************************************
506 * _CIacos (MSVCRT.@)
508 double CDECL _CIacos(void)
510 FPU_DOUBLE(x);
511 return MSVCRT_acos(x);
514 /*********************************************************************
515 * _CIasin (MSVCRT.@)
517 double CDECL _CIasin(void)
519 FPU_DOUBLE(x);
520 return MSVCRT_asin(x);
523 /*********************************************************************
524 * _CIatan (MSVCRT.@)
526 double CDECL _CIatan(void)
528 FPU_DOUBLE(x);
529 return MSVCRT_atan(x);
532 /*********************************************************************
533 * _CIatan2 (MSVCRT.@)
535 double CDECL _CIatan2(void)
537 FPU_DOUBLES(x,y);
538 return MSVCRT_atan2(x,y);
541 /*********************************************************************
542 * _CIcos (MSVCRT.@)
544 double CDECL _CIcos(void)
546 FPU_DOUBLE(x);
547 return MSVCRT_cos(x);
550 /*********************************************************************
551 * _CIcosh (MSVCRT.@)
553 double CDECL _CIcosh(void)
555 FPU_DOUBLE(x);
556 return MSVCRT_cosh(x);
559 /*********************************************************************
560 * _CIexp (MSVCRT.@)
562 double CDECL _CIexp(void)
564 FPU_DOUBLE(x);
565 return MSVCRT_exp(x);
568 /*********************************************************************
569 * _CIfmod (MSVCRT.@)
571 double CDECL _CIfmod(void)
573 FPU_DOUBLES(x,y);
574 return MSVCRT_fmod(x,y);
577 /*********************************************************************
578 * _CIlog (MSVCRT.@)
580 double CDECL _CIlog(void)
582 FPU_DOUBLE(x);
583 return MSVCRT_log(x);
586 /*********************************************************************
587 * _CIlog10 (MSVCRT.@)
589 double CDECL _CIlog10(void)
591 FPU_DOUBLE(x);
592 return MSVCRT_log10(x);
595 /*********************************************************************
596 * _CIpow (MSVCRT.@)
598 double CDECL _CIpow(void)
600 FPU_DOUBLES(x,y);
601 return MSVCRT_pow(x,y);
604 /*********************************************************************
605 * _CIsin (MSVCRT.@)
607 double CDECL _CIsin(void)
609 FPU_DOUBLE(x);
610 return MSVCRT_sin(x);
613 /*********************************************************************
614 * _CIsinh (MSVCRT.@)
616 double CDECL _CIsinh(void)
618 FPU_DOUBLE(x);
619 return MSVCRT_sinh(x);
622 /*********************************************************************
623 * _CIsqrt (MSVCRT.@)
625 double CDECL _CIsqrt(void)
627 FPU_DOUBLE(x);
628 return MSVCRT_sqrt(x);
631 /*********************************************************************
632 * _CItan (MSVCRT.@)
634 double CDECL _CItan(void)
636 FPU_DOUBLE(x);
637 return MSVCRT_tan(x);
640 /*********************************************************************
641 * _CItanh (MSVCRT.@)
643 double CDECL _CItanh(void)
645 FPU_DOUBLE(x);
646 return MSVCRT_tanh(x);
649 /*********************************************************************
650 * _ftol (MSVCRT.@)
652 LONGLONG CDECL MSVCRT__ftol(void)
654 FPU_DOUBLE(x);
655 return (LONGLONG)x;
658 #endif /* defined(__GNUC__) && defined(__i386__) */
660 /*********************************************************************
661 * _fpclass (MSVCRT.@)
663 int CDECL MSVCRT__fpclass(double num)
665 #if defined(HAVE_FPCLASS) || defined(fpclass)
666 switch (fpclass( num ))
668 #ifdef FP_SNAN
669 case FP_SNAN: return MSVCRT__FPCLASS_SNAN;
670 #endif
671 #ifdef FP_QNAN
672 case FP_QNAN: return MSVCRT__FPCLASS_QNAN;
673 #endif
674 #ifdef FP_NINF
675 case FP_NINF: return MSVCRT__FPCLASS_NINF;
676 #endif
677 #ifdef FP_PINF
678 case FP_PINF: return MSVCRT__FPCLASS_PINF;
679 #endif
680 #ifdef FP_NDENORM
681 case FP_NDENORM: return MSVCRT__FPCLASS_ND;
682 #endif
683 #ifdef FP_PDENORM
684 case FP_PDENORM: return MSVCRT__FPCLASS_PD;
685 #endif
686 #ifdef FP_NZERO
687 case FP_NZERO: return MSVCRT__FPCLASS_NZ;
688 #endif
689 #ifdef FP_PZERO
690 case FP_PZERO: return MSVCRT__FPCLASS_PZ;
691 #endif
692 #ifdef FP_NNORM
693 case FP_NNORM: return MSVCRT__FPCLASS_NN;
694 #endif
695 #ifdef FP_PNORM
696 case FP_PNORM: return MSVCRT__FPCLASS_PN;
697 #endif
698 default: return MSVCRT__FPCLASS_PN;
700 #elif defined (fpclassify)
701 switch (fpclassify( num ))
703 case FP_NAN: return MSVCRT__FPCLASS_QNAN;
704 case FP_INFINITE: return signbit(num) ? MSVCRT__FPCLASS_NINF : MSVCRT__FPCLASS_PINF;
705 case FP_SUBNORMAL: return signbit(num) ?MSVCRT__FPCLASS_ND : MSVCRT__FPCLASS_PD;
706 case FP_ZERO: return signbit(num) ? MSVCRT__FPCLASS_NZ : MSVCRT__FPCLASS_PZ;
708 return signbit(num) ? MSVCRT__FPCLASS_NN : MSVCRT__FPCLASS_PN;
709 #else
710 if (!isfinite(num))
711 return MSVCRT__FPCLASS_QNAN;
712 return num == 0.0 ? MSVCRT__FPCLASS_PZ : (num < 0 ? MSVCRT__FPCLASS_NN : MSVCRT__FPCLASS_PN);
713 #endif
716 /*********************************************************************
717 * _rotl (MSVCRT.@)
719 unsigned int CDECL _rotl(unsigned int num, int shift)
721 shift &= 31;
722 return (num << shift) | (num >> (32-shift));
725 /*********************************************************************
726 * _lrotl (MSVCRT.@)
728 MSVCRT_ulong CDECL MSVCRT__lrotl(MSVCRT_ulong num, int shift)
730 shift &= 0x1f;
731 return (num << shift) | (num >> (32-shift));
734 /*********************************************************************
735 * _lrotr (MSVCRT.@)
737 MSVCRT_ulong CDECL MSVCRT__lrotr(MSVCRT_ulong num, int shift)
739 shift &= 0x1f;
740 return (num >> shift) | (num << (32-shift));
743 /*********************************************************************
744 * _rotr (MSVCRT.@)
746 unsigned int CDECL _rotr(unsigned int num, int shift)
748 shift &= 0x1f;
749 return (num >> shift) | (num << (32-shift));
752 /*********************************************************************
753 * _rotl64 (MSVCRT.@)
755 unsigned __int64 CDECL _rotl64(unsigned __int64 num, int shift)
757 shift &= 63;
758 return (num << shift) | (num >> (64-shift));
761 /*********************************************************************
762 * _rotr64 (MSVCRT.@)
764 unsigned __int64 CDECL _rotr64(unsigned __int64 num, int shift)
766 shift &= 63;
767 return (num >> shift) | (num << (64-shift));
770 /*********************************************************************
771 * abs (MSVCRT.@)
773 int CDECL MSVCRT_abs( int n )
775 return n >= 0 ? n : -n;
778 /*********************************************************************
779 * labs (MSVCRT.@)
781 MSVCRT_long CDECL MSVCRT_labs( MSVCRT_long n )
783 return n >= 0 ? n : -n;
786 /*********************************************************************
787 * llabs (MSVCRT.@)
789 MSVCRT_longlong CDECL MSVCRT_llabs( MSVCRT_longlong n )
791 return n >= 0 ? n : -n;
794 /*********************************************************************
795 * _abs64 (MSVCRT.@)
797 __int64 CDECL _abs64( __int64 n )
799 return n >= 0 ? n : -n;
802 /*********************************************************************
803 * _logb (MSVCRT.@)
805 double CDECL MSVCRT__logb(double num)
807 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
808 return logb(num);
811 /*********************************************************************
812 * _hypot (MSVCRT.@)
814 double CDECL _hypot(double x, double y)
816 /* FIXME: errno handling */
817 return hypot( x, y );
820 /*********************************************************************
821 * _hypotf (MSVCRT.@)
823 float CDECL MSVCRT__hypotf(float x, float y)
825 /* FIXME: errno handling */
826 return hypotf( x, y );
829 /*********************************************************************
830 * ceil (MSVCRT.@)
832 double CDECL MSVCRT_ceil( double x )
834 return ceil(x);
837 /*********************************************************************
838 * floor (MSVCRT.@)
840 double CDECL MSVCRT_floor( double x )
842 return floor(x);
845 /*********************************************************************
846 * fabs (MSVCRT.@)
848 double CDECL MSVCRT_fabs( double x )
850 return fabs(x);
853 /*********************************************************************
854 * frexp (MSVCRT.@)
856 double CDECL MSVCRT_frexp( double x, int *exp )
858 return frexp( x, exp );
861 /*********************************************************************
862 * modf (MSVCRT.@)
864 double CDECL MSVCRT_modf( double x, double *iptr )
866 return modf( x, iptr );
869 /*********************************************************************
870 * _matherr (MSVCRT.@)
872 int CDECL MSVCRT__matherr(struct MSVCRT__exception *e)
874 if (e)
875 TRACE("(%p = %d, %s, %g %g %g)\n",e, e->type, e->name, e->arg1, e->arg2,
876 e->retval);
877 else
878 TRACE("(null)\n");
879 if (MSVCRT_default_matherr_func)
880 return MSVCRT_default_matherr_func(e);
881 ERR(":Unhandled math error!\n");
882 return 0;
885 /*********************************************************************
886 * __setusermatherr (MSVCRT.@)
888 void CDECL MSVCRT___setusermatherr(MSVCRT_matherr_func func)
890 MSVCRT_default_matherr_func = func;
891 TRACE(":new matherr handler %p\n", func);
894 /**********************************************************************
895 * _statusfp2 (MSVCRT.@)
897 * Not exported by native msvcrt, added in msvcr80.
899 #if defined(__i386__) || defined(__x86_64__)
900 void CDECL _statusfp2( unsigned int *x86_sw, unsigned int *sse2_sw )
902 #ifdef __GNUC__
903 unsigned int flags;
904 unsigned long fpword;
906 if (x86_sw)
908 __asm__ __volatile__( "fstsw %0" : "=m" (fpword) );
909 flags = 0;
910 if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
911 if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
912 if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
913 if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
914 if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
915 if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
916 *x86_sw = flags;
919 if (!sse2_sw) return;
921 if (sse2_supported)
923 __asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
924 flags = 0;
925 if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
926 if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
927 if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
928 if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
929 if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
930 if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
931 *sse2_sw = flags;
933 else *sse2_sw = 0;
934 #else
935 FIXME( "not implemented\n" );
936 #endif
938 #endif
940 /**********************************************************************
941 * _statusfp (MSVCRT.@)
943 unsigned int CDECL _statusfp(void)
945 #if defined(__i386__) || defined(__x86_64__)
946 unsigned int x86_sw, sse2_sw;
948 _statusfp2( &x86_sw, &sse2_sw );
949 /* FIXME: there's no definition for ambiguous status, just return all status bits for now */
950 return x86_sw | sse2_sw;
951 #else
952 FIXME( "not implemented\n" );
953 return 0;
954 #endif
957 /*********************************************************************
958 * _clearfp (MSVCRT.@)
960 unsigned int CDECL _clearfp(void)
962 unsigned int flags = 0;
963 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
964 unsigned long fpword;
966 __asm__ __volatile__( "fnstsw %0; fnclex" : "=m" (fpword) );
967 if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
968 if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
969 if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
970 if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
971 if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
972 if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
974 if (sse2_supported)
976 __asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
977 if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
978 if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
979 if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
980 if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
981 if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
982 if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
983 fpword &= ~0x3f;
984 __asm__ __volatile__( "ldmxcsr %0" : : "m" (fpword) );
986 #else
987 FIXME( "not implemented\n" );
988 #endif
989 return flags;
992 /*********************************************************************
993 * __fpecode (MSVCRT.@)
995 int * CDECL __fpecode(void)
997 return &msvcrt_get_thread_data()->fpecode;
1000 /*********************************************************************
1001 * ldexp (MSVCRT.@)
1003 double CDECL MSVCRT_ldexp(double num, MSVCRT_long exp)
1005 double z = ldexp(num,exp);
1007 if (!isfinite(z))
1008 *MSVCRT__errno() = MSVCRT_ERANGE;
1009 else if (z == 0 && signbit(z))
1010 z = 0.0; /* Convert -0 -> +0 */
1011 return z;
1014 /*********************************************************************
1015 * _cabs (MSVCRT.@)
1017 double CDECL MSVCRT__cabs(struct MSVCRT__complex num)
1019 return sqrt(num.x * num.x + num.y * num.y);
1022 /*********************************************************************
1023 * _chgsign (MSVCRT.@)
1025 double CDECL MSVCRT__chgsign(double num)
1027 /* FIXME: +-infinity,Nan not tested */
1028 return -num;
1031 /*********************************************************************
1032 * __control87_2 (MSVCRT.@)
1034 * Not exported by native msvcrt, added in msvcr80.
1036 #if defined(__i386__) || defined(__x86_64__)
1037 int CDECL __control87_2( unsigned int newval, unsigned int mask,
1038 unsigned int *x86_cw, unsigned int *sse2_cw )
1040 #ifdef __GNUC__
1041 unsigned long fpword;
1042 unsigned int flags;
1044 if (x86_cw)
1046 __asm__ __volatile__( "fstcw %0" : "=m" (fpword) );
1048 /* Convert into mask constants */
1049 flags = 0;
1050 if (fpword & 0x1) flags |= MSVCRT__EM_INVALID;
1051 if (fpword & 0x2) flags |= MSVCRT__EM_DENORMAL;
1052 if (fpword & 0x4) flags |= MSVCRT__EM_ZERODIVIDE;
1053 if (fpword & 0x8) flags |= MSVCRT__EM_OVERFLOW;
1054 if (fpword & 0x10) flags |= MSVCRT__EM_UNDERFLOW;
1055 if (fpword & 0x20) flags |= MSVCRT__EM_INEXACT;
1056 switch (fpword & 0xc00)
1058 case 0xc00: flags |= MSVCRT__RC_UP|MSVCRT__RC_DOWN; break;
1059 case 0x800: flags |= MSVCRT__RC_UP; break;
1060 case 0x400: flags |= MSVCRT__RC_DOWN; break;
1062 switch (fpword & 0x300)
1064 case 0x0: flags |= MSVCRT__PC_24; break;
1065 case 0x200: flags |= MSVCRT__PC_53; break;
1066 case 0x300: flags |= MSVCRT__PC_64; break;
1068 if (fpword & 0x1000) flags |= MSVCRT__IC_AFFINE;
1070 TRACE( "x86 flags=%08x newval=%08x mask=%08x\n", flags, newval, mask );
1071 if (mask)
1073 flags = (flags & ~mask) | (newval & mask);
1075 /* Convert (masked) value back to fp word */
1076 fpword = 0;
1077 if (flags & MSVCRT__EM_INVALID) fpword |= 0x1;
1078 if (flags & MSVCRT__EM_DENORMAL) fpword |= 0x2;
1079 if (flags & MSVCRT__EM_ZERODIVIDE) fpword |= 0x4;
1080 if (flags & MSVCRT__EM_OVERFLOW) fpword |= 0x8;
1081 if (flags & MSVCRT__EM_UNDERFLOW) fpword |= 0x10;
1082 if (flags & MSVCRT__EM_INEXACT) fpword |= 0x20;
1083 switch (flags & MSVCRT__MCW_RC)
1085 case MSVCRT__RC_UP|MSVCRT__RC_DOWN: fpword |= 0xc00; break;
1086 case MSVCRT__RC_UP: fpword |= 0x800; break;
1087 case MSVCRT__RC_DOWN: fpword |= 0x400; break;
1089 switch (flags & MSVCRT__MCW_PC)
1091 case MSVCRT__PC_64: fpword |= 0x300; break;
1092 case MSVCRT__PC_53: fpword |= 0x200; break;
1093 case MSVCRT__PC_24: fpword |= 0x0; break;
1095 if (flags & MSVCRT__IC_AFFINE) fpword |= 0x1000;
1097 __asm__ __volatile__( "fldcw %0" : : "m" (fpword) );
1099 *x86_cw = flags;
1102 if (!sse2_cw) return 1;
1104 if (sse2_supported)
1106 __asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
1108 /* Convert into mask constants */
1109 flags = 0;
1110 if (fpword & 0x80) flags |= MSVCRT__EM_INVALID;
1111 if (fpword & 0x100) flags |= MSVCRT__EM_DENORMAL;
1112 if (fpword & 0x200) flags |= MSVCRT__EM_ZERODIVIDE;
1113 if (fpword & 0x400) flags |= MSVCRT__EM_OVERFLOW;
1114 if (fpword & 0x800) flags |= MSVCRT__EM_UNDERFLOW;
1115 if (fpword & 0x1000) flags |= MSVCRT__EM_INEXACT;
1116 switch (fpword & 0x6000)
1118 case 0x6000: flags |= MSVCRT__RC_UP|MSVCRT__RC_DOWN; break;
1119 case 0x4000: flags |= MSVCRT__RC_UP; break;
1120 case 0x2000: flags |= MSVCRT__RC_DOWN; break;
1122 switch (fpword & 0x8040)
1124 case 0x0040: flags |= MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS; break;
1125 case 0x8000: flags |= MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS; break;
1126 case 0x8040: flags |= MSVCRT__DN_FLUSH; break;
1129 TRACE( "sse2 flags=%08x newval=%08x mask=%08x\n", flags, newval, mask );
1130 if (mask)
1132 flags = (flags & ~mask) | (newval & mask);
1134 /* Convert (masked) value back to fp word */
1135 fpword = 0;
1136 if (flags & MSVCRT__EM_INVALID) fpword |= 0x80;
1137 if (flags & MSVCRT__EM_DENORMAL) fpword |= 0x100;
1138 if (flags & MSVCRT__EM_ZERODIVIDE) fpword |= 0x200;
1139 if (flags & MSVCRT__EM_OVERFLOW) fpword |= 0x400;
1140 if (flags & MSVCRT__EM_UNDERFLOW) fpword |= 0x800;
1141 if (flags & MSVCRT__EM_INEXACT) fpword |= 0x1000;
1142 switch (flags & MSVCRT__MCW_RC)
1144 case MSVCRT__RC_UP|MSVCRT__RC_DOWN: fpword |= 0x6000; break;
1145 case MSVCRT__RC_UP: fpword |= 0x4000; break;
1146 case MSVCRT__RC_DOWN: fpword |= 0x2000; break;
1148 switch (flags & MSVCRT__MCW_DN)
1150 case MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS: fpword |= 0x0040; break;
1151 case MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS: fpword |= 0x8000; break;
1152 case MSVCRT__DN_FLUSH: fpword |= 0x8040; break;
1154 __asm__ __volatile__( "ldmxcsr %0" : : "m" (fpword) );
1156 *sse2_cw = flags;
1158 else *sse2_cw = 0;
1160 return 1;
1161 #else
1162 FIXME( "not implemented\n" );
1163 return 0;
1164 #endif
1166 #endif
1168 /*********************************************************************
1169 * _control87 (MSVCRT.@)
1171 unsigned int CDECL _control87(unsigned int newval, unsigned int mask)
1173 #if defined(__i386__) || defined(__x86_64__)
1174 unsigned int x86_cw, sse2_cw;
1176 __control87_2( newval, mask, &x86_cw, &sse2_cw );
1178 if ((x86_cw ^ sse2_cw) & (MSVCRT__MCW_EM | MSVCRT__MCW_RC)) x86_cw |= MSVCRT__EM_AMBIGUOUS;
1179 return x86_cw;
1180 #else
1181 FIXME( "not implemented\n" );
1182 return 0;
1183 #endif
1186 /*********************************************************************
1187 * _controlfp (MSVCRT.@)
1189 unsigned int CDECL _controlfp(unsigned int newval, unsigned int mask)
1191 return _control87( newval, mask & ~MSVCRT__EM_DENORMAL );
1194 /*********************************************************************
1195 * _set_controlfp (MSVCRT.@)
1197 void CDECL _set_controlfp( unsigned int newval, unsigned int mask )
1199 _controlfp( newval, mask );
1202 /*********************************************************************
1203 * _controlfp_s (MSVCRT.@)
1205 int CDECL _controlfp_s(unsigned int *cur, unsigned int newval, unsigned int mask)
1207 static const unsigned int all_flags = (MSVCRT__MCW_EM | MSVCRT__MCW_IC | MSVCRT__MCW_RC |
1208 MSVCRT__MCW_PC | MSVCRT__MCW_DN);
1209 unsigned int val;
1211 if (!MSVCRT_CHECK_PMT( !(newval & mask & ~all_flags) ))
1213 if (cur) *cur = _controlfp( 0, 0 ); /* retrieve it anyway */
1214 return MSVCRT_EINVAL;
1216 val = _controlfp( newval, mask );
1217 if (cur) *cur = val;
1218 return 0;
1221 /*********************************************************************
1222 * _copysign (MSVCRT.@)
1224 double CDECL MSVCRT__copysign(double num, double sign)
1226 if (signbit(sign))
1227 return signbit(num) ? num : -num;
1228 return signbit(num) ? -num : num;
1231 /*********************************************************************
1232 * _finite (MSVCRT.@)
1234 int CDECL MSVCRT__finite(double num)
1236 return isfinite(num) != 0; /* See comment for _isnan() */
1239 /*********************************************************************
1240 * _fpreset (MSVCRT.@)
1242 void CDECL _fpreset(void)
1244 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1245 const unsigned int x86_cw = 0x27f;
1246 __asm__ __volatile__( "fninit; fldcw %0" : : "m" (x86_cw) );
1247 if (sse2_supported)
1249 const unsigned long sse2_cw = 0x1f80;
1250 __asm__ __volatile__( "ldmxcsr %0" : : "m" (sse2_cw) );
1252 #else
1253 FIXME( "not implemented\n" );
1254 #endif
1257 /*********************************************************************
1258 * _isnan (MSVCRT.@)
1260 INT CDECL MSVCRT__isnan(double num)
1262 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
1263 * Do the same, as the result may be used in calculations
1265 return isnan(num) != 0;
1268 /*********************************************************************
1269 * _j0 (MSVCRT.@)
1271 double CDECL MSVCRT__j0(double num)
1273 /* FIXME: errno handling */
1274 return j0(num);
1277 /*********************************************************************
1278 * _j1 (MSVCRT.@)
1280 double CDECL MSVCRT__j1(double num)
1282 /* FIXME: errno handling */
1283 return j1(num);
1286 /*********************************************************************
1287 * _jn (MSVCRT.@)
1289 double CDECL MSVCRT__jn(int n, double num)
1291 /* FIXME: errno handling */
1292 return jn(n, num);
1295 /*********************************************************************
1296 * _y0 (MSVCRT.@)
1298 double CDECL MSVCRT__y0(double num)
1300 double retval;
1301 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
1302 retval = y0(num);
1303 if (MSVCRT__fpclass(retval) == MSVCRT__FPCLASS_NINF)
1305 *MSVCRT__errno() = MSVCRT_EDOM;
1306 retval = sqrt(-1);
1308 return retval;
1311 /*********************************************************************
1312 * _y1 (MSVCRT.@)
1314 double CDECL MSVCRT__y1(double num)
1316 double retval;
1317 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
1318 retval = y1(num);
1319 if (MSVCRT__fpclass(retval) == MSVCRT__FPCLASS_NINF)
1321 *MSVCRT__errno() = MSVCRT_EDOM;
1322 retval = sqrt(-1);
1324 return retval;
1327 /*********************************************************************
1328 * _yn (MSVCRT.@)
1330 double CDECL MSVCRT__yn(int order, double num)
1332 double retval;
1333 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
1334 retval = yn(order,num);
1335 if (MSVCRT__fpclass(retval) == MSVCRT__FPCLASS_NINF)
1337 *MSVCRT__errno() = MSVCRT_EDOM;
1338 retval = sqrt(-1);
1340 return retval;
1343 /*********************************************************************
1344 * _nextafter (MSVCRT.@)
1346 double CDECL MSVCRT__nextafter(double num, double next)
1348 double retval;
1349 if (!isfinite(num) || !isfinite(next)) *MSVCRT__errno() = MSVCRT_EDOM;
1350 retval = nextafter(num,next);
1351 return retval;
1354 /*********************************************************************
1355 * _ecvt (MSVCRT.@)
1357 char * CDECL MSVCRT__ecvt( double number, int ndigits, int *decpt, int *sign )
1359 int prec, len;
1360 thread_data_t *data = msvcrt_get_thread_data();
1361 /* FIXME: check better for overflow (native supports over 300 chars) */
1362 ndigits = min( ndigits, 80 - 7); /* 7 : space for dec point, 1 for "e",
1363 * 4 for exponent and one for
1364 * terminating '\0' */
1365 if (!data->efcvt_buffer)
1366 data->efcvt_buffer = MSVCRT_malloc( 80 ); /* ought to be enough */
1368 if( number < 0) {
1369 *sign = TRUE;
1370 number = -number;
1371 } else
1372 *sign = FALSE;
1373 /* handle cases with zero ndigits or less */
1374 prec = ndigits;
1375 if( prec < 1) prec = 2;
1376 len = snprintf(data->efcvt_buffer, 80, "%.*le", prec - 1, number);
1377 /* take the decimal "point away */
1378 if( prec != 1)
1379 memmove( data->efcvt_buffer + 1, data->efcvt_buffer + 2, len - 1 );
1380 /* take the exponential "e" out */
1381 data->efcvt_buffer[ prec] = '\0';
1382 /* read the exponent */
1383 sscanf( data->efcvt_buffer + prec + 1, "%d", decpt);
1384 (*decpt)++;
1385 /* adjust for some border cases */
1386 if( data->efcvt_buffer[0] == '0')/* value is zero */
1387 *decpt = 0;
1388 /* handle cases with zero ndigits or less */
1389 if( ndigits < 1){
1390 if( data->efcvt_buffer[ 0] >= '5')
1391 (*decpt)++;
1392 data->efcvt_buffer[ 0] = '\0';
1394 TRACE("out=\"%s\"\n",data->efcvt_buffer);
1395 return data->efcvt_buffer;
1398 /*********************************************************************
1399 * _ecvt_s (MSVCRT.@)
1401 int CDECL MSVCRT__ecvt_s( char *buffer, MSVCRT_size_t length, double number, int ndigits, int *decpt, int *sign )
1403 int prec, len;
1404 char *result;
1405 const char infret[] = "1#INF";
1407 if (!MSVCRT_CHECK_PMT(buffer != NULL)) return MSVCRT_EINVAL;
1408 if (!MSVCRT_CHECK_PMT(decpt != NULL)) return MSVCRT_EINVAL;
1409 if (!MSVCRT_CHECK_PMT(sign != NULL)) return MSVCRT_EINVAL;
1410 if (!MSVCRT_CHECK_PMT_ERR( length > 2, MSVCRT_ERANGE )) return MSVCRT_ERANGE;
1411 if (!MSVCRT_CHECK_PMT_ERR(ndigits < (int)length - 1, MSVCRT_ERANGE )) return MSVCRT_ERANGE;
1413 /* special case - inf */
1414 if(number == HUGE_VAL || number == -HUGE_VAL)
1416 memset(buffer, '0', ndigits);
1417 memcpy(buffer, infret, min(ndigits, sizeof(infret) - 1 ) );
1418 buffer[ndigits] = '\0';
1419 (*decpt) = 1;
1420 if(number == -HUGE_VAL)
1421 (*sign) = 1;
1422 else
1423 (*sign) = 0;
1424 return 0;
1426 /* handle cases with zero ndigits or less */
1427 prec = ndigits;
1428 if( prec < 1) prec = 2;
1429 result = MSVCRT_malloc(prec + 7);
1431 if( number < 0) {
1432 *sign = TRUE;
1433 number = -number;
1434 } else
1435 *sign = FALSE;
1436 len = snprintf(result, prec + 7, "%.*le", prec - 1, number);
1437 /* take the decimal "point away */
1438 if( prec != 1)
1439 memmove( result + 1, result + 2, len - 1 );
1440 /* take the exponential "e" out */
1441 result[ prec] = '\0';
1442 /* read the exponent */
1443 sscanf( result + prec + 1, "%d", decpt);
1444 (*decpt)++;
1445 /* adjust for some border cases */
1446 if( result[0] == '0')/* value is zero */
1447 *decpt = 0;
1448 /* handle cases with zero ndigits or less */
1449 if( ndigits < 1){
1450 if( result[ 0] >= '5')
1451 (*decpt)++;
1452 result[ 0] = '\0';
1454 memcpy( buffer, result, max(ndigits + 1, 1) );
1455 MSVCRT_free( result );
1456 return 0;
1459 /***********************************************************************
1460 * _fcvt (MSVCRT.@)
1462 char * CDECL MSVCRT__fcvt( double number, int ndigits, int *decpt, int *sign )
1464 thread_data_t *data = msvcrt_get_thread_data();
1465 int stop, dec1, dec2;
1466 char *ptr1, *ptr2, *first;
1467 char buf[80]; /* ought to be enough */
1469 if (!data->efcvt_buffer)
1470 data->efcvt_buffer = MSVCRT_malloc( 80 ); /* ought to be enough */
1472 if (number < 0)
1474 *sign = 1;
1475 number = -number;
1476 } else *sign = 0;
1478 snprintf(buf, 80, "%.*f", ndigits < 0 ? 0 : ndigits, number);
1479 ptr1 = buf;
1480 ptr2 = data->efcvt_buffer;
1481 first = NULL;
1482 dec1 = 0;
1483 dec2 = 0;
1485 /* For numbers below the requested resolution, work out where
1486 the decimal point will be rather than finding it in the string */
1487 if (number < 1.0 && number > 0.0) {
1488 dec2 = log10(number + 1e-10);
1489 if (-dec2 <= ndigits) dec2 = 0;
1492 /* If requested digits is zero or less, we will need to truncate
1493 * the returned string */
1494 if (ndigits < 1) {
1495 stop = strlen(buf) + ndigits;
1496 } else {
1497 stop = strlen(buf);
1500 while (*ptr1 == '0') ptr1++; /* Skip leading zeroes */
1501 while (*ptr1 != '\0' && *ptr1 != '.') {
1502 if (!first) first = ptr2;
1503 if ((ptr1 - buf) < stop) {
1504 *ptr2++ = *ptr1++;
1505 } else {
1506 ptr1++;
1508 dec1++;
1511 if (ndigits > 0) {
1512 ptr1++;
1513 if (!first) {
1514 while (*ptr1 == '0') { /* Process leading zeroes */
1515 *ptr2++ = *ptr1++;
1516 dec1--;
1519 while (*ptr1 != '\0') {
1520 if (!first) first = ptr2;
1521 *ptr2++ = *ptr1++;
1525 *ptr2 = '\0';
1527 /* We never found a non-zero digit, then our number is either
1528 * smaller than the requested precision, or 0.0 */
1529 if (!first) {
1530 if (number > 0.0) {
1531 first = ptr2;
1532 } else {
1533 first = data->efcvt_buffer;
1534 dec1 = 0;
1538 *decpt = dec2 ? dec2 : dec1;
1539 return first;
1542 /***********************************************************************
1543 * _fcvt_s (MSVCRT.@)
1545 int CDECL MSVCRT__fcvt_s(char* outbuffer, MSVCRT_size_t size, double number, int ndigits, int *decpt, int *sign)
1547 int stop, dec1, dec2;
1548 char *ptr1, *ptr2, *first;
1549 char buf[80]; /* ought to be enough */
1551 if (!outbuffer || !decpt || !sign || size == 0)
1553 *MSVCRT__errno() = MSVCRT_EINVAL;
1554 return MSVCRT_EINVAL;
1557 if (number < 0)
1559 *sign = 1;
1560 number = -number;
1561 } else *sign = 0;
1563 snprintf(buf, 80, "%.*f", ndigits < 0 ? 0 : ndigits, number);
1564 ptr1 = buf;
1565 ptr2 = outbuffer;
1566 first = NULL;
1567 dec1 = 0;
1568 dec2 = 0;
1570 /* For numbers below the requested resolution, work out where
1571 the decimal point will be rather than finding it in the string */
1572 if (number < 1.0 && number > 0.0) {
1573 dec2 = log10(number + 1e-10);
1574 if (-dec2 <= ndigits) dec2 = 0;
1577 /* If requested digits is zero or less, we will need to truncate
1578 * the returned string */
1579 if (ndigits < 1) {
1580 stop = strlen(buf) + ndigits;
1581 } else {
1582 stop = strlen(buf);
1585 while (*ptr1 == '0') ptr1++; /* Skip leading zeroes */
1586 while (*ptr1 != '\0' && *ptr1 != '.') {
1587 if (!first) first = ptr2;
1588 if ((ptr1 - buf) < stop) {
1589 if (size > 1) {
1590 *ptr2++ = *ptr1++;
1591 size--;
1593 } else {
1594 ptr1++;
1596 dec1++;
1599 if (ndigits > 0) {
1600 ptr1++;
1601 if (!first) {
1602 while (*ptr1 == '0') { /* Process leading zeroes */
1603 if (number == 0.0 && size > 1) {
1604 *ptr2++ = '0';
1605 size--;
1607 ptr1++;
1608 dec1--;
1611 while (*ptr1 != '\0') {
1612 if (!first) first = ptr2;
1613 if (size > 1) {
1614 *ptr2++ = *ptr1++;
1615 size--;
1620 *ptr2 = '\0';
1622 /* We never found a non-zero digit, then our number is either
1623 * smaller than the requested precision, or 0.0 */
1624 if (!first && (number <= 0.0))
1625 dec1 = 0;
1627 *decpt = dec2 ? dec2 : dec1;
1628 return 0;
1631 /***********************************************************************
1632 * _gcvt (MSVCRT.@)
1634 char * CDECL MSVCRT__gcvt( double number, int ndigit, char *buff )
1636 if(!buff) {
1637 *MSVCRT__errno() = MSVCRT_EINVAL;
1638 return NULL;
1641 if(ndigit < 0) {
1642 *MSVCRT__errno() = MSVCRT_ERANGE;
1643 return NULL;
1646 MSVCRT_sprintf(buff, "%.*g", ndigit, number);
1647 return buff;
1650 /***********************************************************************
1651 * _gcvt_s (MSVCRT.@)
1653 int CDECL MSVCRT__gcvt_s(char *buff, MSVCRT_size_t size, double number, int digits)
1655 int len;
1657 if(!buff) {
1658 *MSVCRT__errno() = MSVCRT_EINVAL;
1659 return MSVCRT_EINVAL;
1662 if( digits<0 || digits>=size) {
1663 if(size)
1664 buff[0] = '\0';
1666 *MSVCRT__errno() = MSVCRT_ERANGE;
1667 return MSVCRT_ERANGE;
1670 len = MSVCRT__scprintf("%.*g", digits, number);
1671 if(len > size) {
1672 buff[0] = '\0';
1673 *MSVCRT__errno() = MSVCRT_ERANGE;
1674 return MSVCRT_ERANGE;
1677 MSVCRT_sprintf(buff, "%.*g", digits, number);
1678 return 0;
1681 #include <stdlib.h> /* div_t, ldiv_t */
1683 /*********************************************************************
1684 * div (MSVCRT.@)
1685 * VERSION
1686 * [i386] Windows binary compatible - returns the struct in eax/edx.
1688 #ifdef __i386__
1689 unsigned __int64 CDECL MSVCRT_div(int num, int denom)
1691 div_t dt = div(num,denom);
1692 return ((unsigned __int64)dt.rem << 32) | (unsigned int)dt.quot;
1694 #else
1695 /*********************************************************************
1696 * div (MSVCRT.@)
1697 * VERSION
1698 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
1700 MSVCRT_div_t CDECL MSVCRT_div(int num, int denom)
1702 div_t dt = div(num,denom);
1703 MSVCRT_div_t ret;
1704 ret.quot = dt.quot;
1705 ret.rem = dt.rem;
1707 return ret;
1710 #endif /* ifdef __i386__ */
1713 /*********************************************************************
1714 * ldiv (MSVCRT.@)
1715 * VERSION
1716 * [i386] Windows binary compatible - returns the struct in eax/edx.
1718 #ifdef __i386__
1719 unsigned __int64 CDECL MSVCRT_ldiv(MSVCRT_long num, MSVCRT_long denom)
1721 ldiv_t ldt = ldiv(num,denom);
1722 return ((unsigned __int64)ldt.rem << 32) | (MSVCRT_ulong)ldt.quot;
1724 #else
1725 /*********************************************************************
1726 * ldiv (MSVCRT.@)
1727 * VERSION
1728 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
1730 MSVCRT_ldiv_t CDECL MSVCRT_ldiv(MSVCRT_long num, MSVCRT_long denom)
1732 ldiv_t result = ldiv(num,denom);
1734 MSVCRT_ldiv_t ret;
1735 ret.quot = result.quot;
1736 ret.rem = result.rem;
1738 return ret;
1740 #endif /* ifdef __i386__ */
1742 #ifdef __i386__
1744 /*********************************************************************
1745 * _adjust_fdiv (MSVCRT.@)
1746 * Used by the MSVC compiler to work around the Pentium FDIV bug.
1748 int MSVCRT__adjust_fdiv = 0;
1750 /***********************************************************************
1751 * _adj_fdiv_m16i (MSVCRT.@)
1753 * NOTE
1754 * I _think_ this function is intended to work around the Pentium
1755 * fdiv bug.
1757 void __stdcall _adj_fdiv_m16i( short arg )
1759 TRACE("(): stub\n");
1762 /***********************************************************************
1763 * _adj_fdiv_m32 (MSVCRT.@)
1765 * NOTE
1766 * I _think_ this function is intended to work around the Pentium
1767 * fdiv bug.
1769 void __stdcall _adj_fdiv_m32( unsigned int arg )
1771 TRACE("(): stub\n");
1774 /***********************************************************************
1775 * _adj_fdiv_m32i (MSVCRT.@)
1777 * NOTE
1778 * I _think_ this function is intended to work around the Pentium
1779 * fdiv bug.
1781 void __stdcall _adj_fdiv_m32i( int arg )
1783 TRACE("(): stub\n");
1786 /***********************************************************************
1787 * _adj_fdiv_m64 (MSVCRT.@)
1789 * NOTE
1790 * I _think_ this function is intended to work around the Pentium
1791 * fdiv bug.
1793 void __stdcall _adj_fdiv_m64( unsigned __int64 arg )
1795 TRACE("(): stub\n");
1798 /***********************************************************************
1799 * _adj_fdiv_r (MSVCRT.@)
1800 * FIXME
1801 * This function is likely to have the wrong number of arguments.
1803 * NOTE
1804 * I _think_ this function is intended to work around the Pentium
1805 * fdiv bug.
1807 void _adj_fdiv_r(void)
1809 TRACE("(): stub\n");
1812 /***********************************************************************
1813 * _adj_fdivr_m16i (MSVCRT.@)
1815 * NOTE
1816 * I _think_ this function is intended to work around the Pentium
1817 * fdiv bug.
1819 void __stdcall _adj_fdivr_m16i( short arg )
1821 TRACE("(): stub\n");
1824 /***********************************************************************
1825 * _adj_fdivr_m32 (MSVCRT.@)
1827 * NOTE
1828 * I _think_ this function is intended to work around the Pentium
1829 * fdiv bug.
1831 void __stdcall _adj_fdivr_m32( unsigned int arg )
1833 TRACE("(): stub\n");
1836 /***********************************************************************
1837 * _adj_fdivr_m32i (MSVCRT.@)
1839 * NOTE
1840 * I _think_ this function is intended to work around the Pentium
1841 * fdiv bug.
1843 void __stdcall _adj_fdivr_m32i( int arg )
1845 TRACE("(): stub\n");
1848 /***********************************************************************
1849 * _adj_fdivr_m64 (MSVCRT.@)
1851 * NOTE
1852 * I _think_ this function is intended to work around the Pentium
1853 * fdiv bug.
1855 void __stdcall _adj_fdivr_m64( unsigned __int64 arg )
1857 TRACE("(): stub\n");
1860 /***********************************************************************
1861 * _adj_fpatan (MSVCRT.@)
1862 * FIXME
1863 * This function is likely to have the wrong number of arguments.
1865 * NOTE
1866 * I _think_ this function is intended to work around the Pentium
1867 * fdiv bug.
1869 void _adj_fpatan(void)
1871 TRACE("(): stub\n");
1874 /***********************************************************************
1875 * _adj_fprem (MSVCRT.@)
1876 * FIXME
1877 * This function is likely to have the wrong number of arguments.
1879 * NOTE
1880 * I _think_ this function is intended to work around the Pentium
1881 * fdiv bug.
1883 void _adj_fprem(void)
1885 TRACE("(): stub\n");
1888 /***********************************************************************
1889 * _adj_fprem1 (MSVCRT.@)
1890 * FIXME
1891 * This function is likely to have the wrong number of arguments.
1893 * NOTE
1894 * I _think_ this function is intended to work around the Pentium
1895 * fdiv bug.
1897 void _adj_fprem1(void)
1899 TRACE("(): stub\n");
1902 /***********************************************************************
1903 * _adj_fptan (MSVCRT.@)
1904 * FIXME
1905 * This function is likely to have the wrong number of arguments.
1907 * NOTE
1908 * I _think_ this function is intended to work around the Pentium
1909 * fdiv bug.
1911 void _adj_fptan(void)
1913 TRACE("(): stub\n");
1916 /***********************************************************************
1917 * _safe_fdiv (MSVCRT.@)
1918 * FIXME
1919 * This function is likely to have the wrong number of arguments.
1921 * NOTE
1922 * I _think_ this function is intended to work around the Pentium
1923 * fdiv bug.
1925 void _safe_fdiv(void)
1927 TRACE("(): stub\n");
1930 /***********************************************************************
1931 * _safe_fdivr (MSVCRT.@)
1932 * FIXME
1933 * This function is likely to have the wrong number of arguments.
1935 * NOTE
1936 * I _think_ this function is intended to work around the Pentium
1937 * fdiv bug.
1939 void _safe_fdivr(void)
1941 TRACE("(): stub\n");
1944 /***********************************************************************
1945 * _safe_fprem (MSVCRT.@)
1946 * FIXME
1947 * This function is likely to have the wrong number of arguments.
1949 * NOTE
1950 * I _think_ this function is intended to work around the Pentium
1951 * fdiv bug.
1953 void _safe_fprem(void)
1955 TRACE("(): stub\n");
1958 /***********************************************************************
1959 * _safe_fprem1 (MSVCRT.@)
1961 * FIXME
1962 * This function is likely to have the wrong number of arguments.
1964 * NOTE
1965 * I _think_ this function is intended to work around the Pentium
1966 * fdiv bug.
1968 void _safe_fprem1(void)
1970 TRACE("(): stub\n");
1973 /***********************************************************************
1974 * __libm_sse2_acos (MSVCRT.@)
1976 void __cdecl MSVCRT___libm_sse2_acos(void)
1978 double d;
1979 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
1980 d = acos( d );
1981 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
1984 /***********************************************************************
1985 * __libm_sse2_acosf (MSVCRT.@)
1987 void __cdecl MSVCRT___libm_sse2_acosf(void)
1989 float f;
1990 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
1991 f = acosf( f );
1992 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
1995 /***********************************************************************
1996 * __libm_sse2_asin (MSVCRT.@)
1998 void __cdecl MSVCRT___libm_sse2_asin(void)
2000 double d;
2001 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2002 d = asin( d );
2003 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2006 /***********************************************************************
2007 * __libm_sse2_asinf (MSVCRT.@)
2009 void __cdecl MSVCRT___libm_sse2_asinf(void)
2011 float f;
2012 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2013 f = asinf( f );
2014 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2017 /***********************************************************************
2018 * __libm_sse2_atan (MSVCRT.@)
2020 void __cdecl MSVCRT___libm_sse2_atan(void)
2022 double d;
2023 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2024 d = atan( d );
2025 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2028 /***********************************************************************
2029 * __libm_sse2_atan2 (MSVCRT.@)
2031 void __cdecl MSVCRT___libm_sse2_atan2(void)
2033 double d1, d2;
2034 __asm__ __volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1), "=m" (d2) );
2035 d1 = atan2( d1, d2 );
2036 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d1) );
2039 /***********************************************************************
2040 * __libm_sse2_atanf (MSVCRT.@)
2042 void __cdecl MSVCRT___libm_sse2_atanf(void)
2044 float f;
2045 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2046 f = atanf( f );
2047 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2050 /***********************************************************************
2051 * __libm_sse2_cos (MSVCRT.@)
2053 void __cdecl MSVCRT___libm_sse2_cos(void)
2055 double d;
2056 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2057 d = cos( d );
2058 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2061 /***********************************************************************
2062 * __libm_sse2_cosf (MSVCRT.@)
2064 void __cdecl MSVCRT___libm_sse2_cosf(void)
2066 float f;
2067 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2068 f = cosf( f );
2069 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2072 /***********************************************************************
2073 * __libm_sse2_exp (MSVCRT.@)
2075 void __cdecl MSVCRT___libm_sse2_exp(void)
2077 double d;
2078 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2079 d = exp( d );
2080 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2083 /***********************************************************************
2084 * __libm_sse2_expf (MSVCRT.@)
2086 void __cdecl MSVCRT___libm_sse2_expf(void)
2088 float f;
2089 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2090 f = expf( f );
2091 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2094 /***********************************************************************
2095 * __libm_sse2_log (MSVCRT.@)
2097 void __cdecl MSVCRT___libm_sse2_log(void)
2099 double d;
2100 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2101 d = log( d );
2102 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2105 /***********************************************************************
2106 * __libm_sse2_log10 (MSVCRT.@)
2108 void __cdecl MSVCRT___libm_sse2_log10(void)
2110 double d;
2111 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2112 d = log10( d );
2113 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2116 /***********************************************************************
2117 * __libm_sse2_log10f (MSVCRT.@)
2119 void __cdecl MSVCRT___libm_sse2_log10f(void)
2121 float f;
2122 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2123 f = log10f( f );
2124 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2127 /***********************************************************************
2128 * __libm_sse2_logf (MSVCRT.@)
2130 void __cdecl MSVCRT___libm_sse2_logf(void)
2132 float f;
2133 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2134 f = logf( f );
2135 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2138 /***********************************************************************
2139 * __libm_sse2_pow (MSVCRT.@)
2141 void __cdecl MSVCRT___libm_sse2_pow(void)
2143 double d1, d2;
2144 __asm__ __volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1), "=m" (d2) );
2145 d1 = pow( d1, d2 );
2146 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d1) );
2149 /***********************************************************************
2150 * __libm_sse2_powf (MSVCRT.@)
2152 void __cdecl MSVCRT___libm_sse2_powf(void)
2154 float f1, f2;
2155 __asm__ __volatile__( "movd %%xmm0,%0; movd %%xmm1,%1" : "=g" (f1), "=g" (f2) );
2156 f1 = powf( f1, f2 );
2157 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f1) );
2160 /***********************************************************************
2161 * __libm_sse2_sin (MSVCRT.@)
2163 void __cdecl MSVCRT___libm_sse2_sin(void)
2165 double d;
2166 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2167 d = sin( d );
2168 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2171 /***********************************************************************
2172 * __libm_sse2_sinf (MSVCRT.@)
2174 void __cdecl MSVCRT___libm_sse2_sinf(void)
2176 float f;
2177 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2178 f = sinf( f );
2179 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2182 /***********************************************************************
2183 * __libm_sse2_tan (MSVCRT.@)
2185 void __cdecl MSVCRT___libm_sse2_tan(void)
2187 double d;
2188 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2189 d = tan( d );
2190 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2193 /***********************************************************************
2194 * __libm_sse2_tanf (MSVCRT.@)
2196 void __cdecl MSVCRT___libm_sse2_tanf(void)
2198 float f;
2199 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2200 f = tanf( f );
2201 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2204 /***********************************************************************
2205 * __libm_sse2_sqrt_precise (MSVCR110.@)
2207 void __cdecl MSVCRT___libm_sse2_sqrt_precise(void)
2209 double d;
2210 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2211 d = sqrt( d );
2212 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2215 #endif /* __i386__ */
2217 /*********************************************************************
2218 * cbrt (MSVCR120.@)
2220 double CDECL MSVCR120_cbrt(double x)
2222 #ifdef HAVE_CBRT
2223 return cbrt(x);
2224 #else
2225 return x < 0 ? -pow(-x, 1.0 / 3.0) : pow(x, 1.0 / 3.0);
2226 #endif
2229 /*********************************************************************
2230 * cbrtf (MSVCR120.@)
2232 float CDECL MSVCR120_cbrtf(float x)
2234 #ifdef HAVE_CBRTF
2235 return cbrtf(x);
2236 #else
2237 return MSVCR120_cbrt(x);
2238 #endif
2241 /*********************************************************************
2242 * cbrtl (MSVCR120.@)
2244 LDOUBLE CDECL MSVCR120_cbrtl(LDOUBLE x)
2246 return MSVCR120_cbrt(x);
2249 /*********************************************************************
2250 * exp2 (MSVCR120.@)
2252 double CDECL MSVCR120_exp2(double x)
2254 #ifdef HAVE_EXP2
2255 return exp2(x);
2256 #else
2257 return pow(2, x);
2258 #endif
2261 /*********************************************************************
2262 * exp2f (MSVCR120.@)
2264 float CDECL MSVCR120_exp2f(float x)
2266 #ifdef HAVE_EXP2F
2267 return exp2f(x);
2268 #else
2269 return MSVCR120_exp2(x);
2270 #endif
2273 /*********************************************************************
2274 * exp2l (MSVCR120.@)
2276 LDOUBLE CDECL MSVCR120_exp2l(LDOUBLE x)
2278 return MSVCR120_exp2(x);
2281 /*********************************************************************
2282 * log2 (MSVCR120.@)
2284 double CDECL MSVCR120_log2(double x)
2286 #ifdef HAVE_LOG2
2287 return log2(x);
2288 #else
2289 return log(x) / log(2);
2290 #endif
2293 /*********************************************************************
2294 * log2f (MSVCR120.@)
2296 float CDECL MSVCR120_log2f(float x)
2298 #ifdef HAVE_LOG2F
2299 return log2f(x);
2300 #else
2301 return MSVCR120_log2(x);
2302 #endif
2305 /*********************************************************************
2306 * log2l (MSVCR120.@)
2308 LDOUBLE CDECL MSVCR120_log2l(LDOUBLE x)
2310 return MSVCR120_log2(x);
2313 /*********************************************************************
2314 * rint (MSVCR120.@)
2316 double CDECL MSVCR120_rint(double x)
2318 #ifdef HAVE_RINT
2319 return rint(x);
2320 #else
2321 return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
2322 #endif
2325 /*********************************************************************
2326 * rintf (MSVCR120.@)
2328 float CDECL MSVCR120_rintf(float x)
2330 #ifdef HAVE_RINTF
2331 return rintf(x);
2332 #else
2333 return MSVCR120_rint(x);
2334 #endif
2337 /*********************************************************************
2338 * rintl (MSVCR120.@)
2340 LDOUBLE CDECL MSVCR120_rintl(LDOUBLE x)
2342 return MSVCR120_rint(x);
2345 /*********************************************************************
2346 * lrint (MSVCR120.@)
2348 MSVCRT_long CDECL MSVCR120_lrint(double x)
2350 #ifdef HAVE_LRINT
2351 return lrint(x);
2352 #else
2353 return MSVCR120_rint(x);
2354 #endif
2357 /*********************************************************************
2358 * lrintf (MSVCR120.@)
2360 MSVCRT_long CDECL MSVCR120_lrintf(float x)
2362 #ifdef HAVE_LRINTF
2363 return lrintf(x);
2364 #else
2365 return MSVCR120_lrint(x);
2366 #endif
2369 /*********************************************************************
2370 * lrintl (MSVCR120.@)
2372 MSVCRT_long CDECL MSVCR120_lrintl(LDOUBLE x)
2374 return MSVCR120_lrint(x);
2377 /*********************************************************************
2378 * llrint (MSVCR120.@)
2380 MSVCRT_longlong CDECL MSVCR120_llrint(double x)
2382 #ifdef HAVE_LLRINT
2383 return llrint(x);
2384 #else
2385 return MSVCR120_rint(x);
2386 #endif
2389 /*********************************************************************
2390 * llrintf (MSVCR120.@)
2392 MSVCRT_longlong CDECL MSVCR120_llrintf(float x)
2394 #ifdef HAVE_LLRINTF
2395 return llrintf(x);
2396 #else
2397 return MSVCR120_llrint(x);
2398 #endif
2401 /*********************************************************************
2402 * rintl (MSVCR120.@)
2404 MSVCRT_longlong CDECL MSVCR120_llrintl(LDOUBLE x)
2406 return MSVCR120_llrint(x);
2409 /*********************************************************************
2410 * round (MSVCR120.@)
2412 double CDECL MSVCR120_round(double x)
2414 #ifdef HAVE_ROUND
2415 return round(x);
2416 #else
2417 return MSVCR120_rint(x);
2418 #endif
2421 /*********************************************************************
2422 * roundf (MSVCR120.@)
2424 float CDECL MSVCR120_roundf(float x)
2426 #ifdef HAVE_ROUNDF
2427 return roundf(x);
2428 #else
2429 return MSVCR120_round(x);
2430 #endif
2433 /*********************************************************************
2434 * roundl (MSVCR120.@)
2436 LDOUBLE CDECL MSVCR120_roundl(LDOUBLE x)
2438 return MSVCR120_round(x);
2441 /*********************************************************************
2442 * lround (MSVCR120.@)
2444 MSVCRT_long CDECL MSVCR120_lround(double x)
2446 #ifdef HAVE_LROUND
2447 return lround(x);
2448 #else
2449 return MSVCR120_round(x);
2450 #endif
2453 /*********************************************************************
2454 * lroundf (MSVCR120.@)
2456 MSVCRT_long CDECL MSVCR120_lroundf(float x)
2458 #ifdef HAVE_LROUNDF
2459 return lroundf(x);
2460 #else
2461 return MSVCR120_lround(x);
2462 #endif
2465 /*********************************************************************
2466 * lroundl (MSVCR120.@)
2468 MSVCRT_long CDECL MSVCR120_lroundl(LDOUBLE x)
2470 return MSVCR120_lround(x);
2473 /*********************************************************************
2474 * llround (MSVCR120.@)
2476 MSVCRT_longlong CDECL MSVCR120_llround(double x)
2478 #ifdef HAVE_LLROUND
2479 return llround(x);
2480 #else
2481 return MSVCR120_round(x);
2482 #endif
2485 /*********************************************************************
2486 * llroundf (MSVCR120.@)
2488 MSVCRT_longlong CDECL MSVCR120_llroundf(float x)
2490 #ifdef HAVE_LLROUNDF
2491 return llroundf(x);
2492 #else
2493 return MSVCR120_llround(x);
2494 #endif
2497 /*********************************************************************
2498 * roundl (MSVCR120.@)
2500 MSVCRT_longlong CDECL MSVCR120_llroundl(LDOUBLE x)
2502 return MSVCR120_llround(x);
2505 /*********************************************************************
2506 * trunc (MSVCR120.@)
2508 double CDECL MSVCR120_trunc(double x)
2510 #ifdef HAVE_TRUNC
2511 return trunc(x);
2512 #else
2513 return (x > 0) ? floor(x) : ceil(x);
2514 #endif
2517 /*********************************************************************
2518 * truncf (MSVCR120.@)
2520 float CDECL MSVCR120_truncf(float x)
2522 #ifdef HAVE_TRUNCF
2523 return truncf(x);
2524 #else
2525 return MSVCR120_trunc(x);
2526 #endif
2529 /*********************************************************************
2530 * truncl (MSVCR120.@)
2532 LDOUBLE CDECL MSVCR120_truncl(LDOUBLE x)
2534 return MSVCR120_trunc(x);
2537 /*********************************************************************
2538 * _dclass (MSVCR120.@)
2540 short CDECL MSVCR120__dclass(double x)
2542 switch (MSVCRT__fpclass(x)) {
2543 case MSVCRT__FPCLASS_QNAN:
2544 case MSVCRT__FPCLASS_SNAN:
2545 return MSVCRT_FP_NAN;
2546 case MSVCRT__FPCLASS_NINF:
2547 case MSVCRT__FPCLASS_PINF:
2548 return MSVCRT_FP_INFINITE;
2549 case MSVCRT__FPCLASS_ND:
2550 case MSVCRT__FPCLASS_PD:
2551 return MSVCRT_FP_SUBNORMAL;
2552 case MSVCRT__FPCLASS_NN:
2553 case MSVCRT__FPCLASS_PN:
2554 default:
2555 return MSVCRT_FP_NORMAL;
2556 case MSVCRT__FPCLASS_NZ:
2557 case MSVCRT__FPCLASS_PZ:
2558 return MSVCRT_FP_ZERO;
2562 /*********************************************************************
2563 * _fdclass (MSVCR120.@)
2565 short CDECL MSVCR120__fdclass(float x)
2567 return MSVCR120__dclass(x);
2570 /*********************************************************************
2571 * _ldclass (MSVCR120.@)
2573 short CDECL MSVCR120__ldclass(LDOUBLE x)
2575 return MSVCR120__dclass(x);
2578 /*********************************************************************
2579 * _dtest (MSVCR120.@)
2581 short CDECL MSVCR120__dtest(double *x)
2583 return MSVCR120__dclass(*x);
2586 /*********************************************************************
2587 * _fdtest (MSVCR120.@)
2589 short CDECL MSVCR120__fdtest(float *x)
2591 return MSVCR120__dclass(*x);
2594 /*********************************************************************
2595 * _ldtest (MSVCR120.@)
2597 short CDECL MSVCR120__ldtest(LDOUBLE *x)
2599 return MSVCR120__dclass(*x);
2602 /*********************************************************************
2603 * erff (MSVCR120.@)
2605 float CDECL MSVCR120_erff(float x)
2607 #ifdef HAVE_ERFF
2608 return erff(x);
2609 #else
2610 FIXME( "not implemented\n" );
2611 return 0.0f;
2612 #endif
2615 /*********************************************************************
2616 * erf (MSVCR120.@)
2618 double CDECL MSVCR120_erf(double x)
2620 #ifdef HAVE_ERF
2621 return erf(x);
2622 #else
2623 FIXME( "not implemented\n" );
2624 return 0.0;
2625 #endif
2628 /*********************************************************************
2629 * erfl (MSVCR120.@)
2631 LDOUBLE CDECL MSVCR120_erfl(LDOUBLE x)
2633 return MSVCR120_erf(x);
2636 /*********************************************************************
2637 * fmaxf (MSVCR120.@)
2639 float CDECL MSVCR120_fmaxf(float x, float y)
2641 if(isnanf(x))
2642 return y;
2643 if(isnanf(y))
2644 return x;
2645 if(x==0 && y==0)
2646 return signbit(x) ? y : x;
2647 return x<y ? y : x;
2650 /*********************************************************************
2651 * fmax (MSVCR120.@)
2653 double CDECL MSVCR120_fmax(double x, double y)
2655 if(isnan(x))
2656 return y;
2657 if(isnan(y))
2658 return x;
2659 if(x==0 && y==0)
2660 return signbit(x) ? y : x;
2661 return x<y ? y : x;
2664 /*********************************************************************
2665 * _fdsign (MSVCR120.@)
2667 int CDECL MSVCR120__fdsign(float x)
2669 return signbit(x) ? 0x8000 : 0;
2672 /*********************************************************************
2673 * _dsign (MSVCR120.@)
2675 int CDECL MSVCR120__dsign(double x)
2677 return signbit(x) ? 0x8000 : 0;
2681 /*********************************************************************
2682 * _dpcomp (MSVCR120.@)
2684 int CDECL MSVCR120__dpcomp(double x, double y)
2686 if(isnan(x) || isnan(y))
2687 return 0;
2689 if(x == y) return 2;
2690 return x < y ? 1 : 4;
2693 /*********************************************************************
2694 * _fdpcomp (MSVCR120.@)
2696 int CDECL MSVCR120__fdpcomp(float x, float y)
2698 return MSVCR120__dpcomp(x, y);
2701 /*********************************************************************
2702 * fminf (MSVCR120.@)
2704 float CDECL MSVCR120_fminf(float x, float y)
2706 if(isnanf(x))
2707 return y;
2708 if(isnanf(y))
2709 return x;
2710 if(x==0 && y==0)
2711 return signbit(x) ? x : y;
2712 return x<y ? x : y;
2715 /*********************************************************************
2716 * fmin (MSVCR120.@)
2718 double CDECL MSVCR120_fmin(double x, double y)
2720 if(isnan(x))
2721 return y;
2722 if(isnan(y))
2723 return x;
2724 if(x==0 && y==0)
2725 return signbit(x) ? x : y;
2726 return x<y ? x : y;
2729 /*********************************************************************
2730 * asinh (MSVCR120.@)
2732 double CDECL MSVCR120_asinh(double x)
2734 #ifdef HAVE_ASINH
2735 return asinh(x);
2736 #else
2737 FIXME( "not implemented\n" );
2738 return 0.0;
2739 #endif
2742 /*********************************************************************
2743 * asinhf (MSVCR120.@)
2745 float CDECL MSVCR120_asinhf(float x)
2747 #ifdef HAVE_ASINHF
2748 return asinhf(x);
2749 #else
2750 FIXME( "not implemented\n" );
2751 return 0.0f;
2752 #endif
2755 /*********************************************************************
2756 * asinhl (MSVCR120.@)
2758 LDOUBLE CDECL MSVCR120_asinhl(LDOUBLE x)
2760 return MSVCR120_asinh(x);
2763 /*********************************************************************
2764 * _scalb (MSVCRT.@)
2765 * scalbn (MSVCR120.@)
2766 * scalbln (MSVCR120.@)
2768 double CDECL MSVCRT__scalb(double num, MSVCRT_long power)
2770 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
2771 return ldexp(num, power);
2774 /*********************************************************************
2775 * _scalbf (MSVCRT.@)
2776 * scalbnf (MSVCR120.@)
2777 * scalblnf (MSVCR120.@)
2779 float CDECL MSVCRT__scalbf(float num, MSVCRT_long power)
2781 if (!finitef(num)) *MSVCRT__errno() = MSVCRT_EDOM;
2782 return ldexpf(num, power);
2785 /*********************************************************************
2786 * scalbnl (MSVCR120.@)
2787 * scalblnl (MSVCR120.@)
2789 LDOUBLE CDECL MSVCR120_scalbnl(LDOUBLE num, MSVCRT_long power)
2791 return MSVCRT__scalb(num, power);
2794 /*********************************************************************
2795 * remainder (MSVCR120.@)
2797 double CDECL MSVCR120_remainder(double x, double y)
2799 #ifdef HAVE_REMAINDER
2800 /* this matches 64-bit Windows. 32-bit Windows is slightly different */
2801 if(!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
2802 if(isnan(y) || y==0.0) *MSVCRT__errno() = MSVCRT_EDOM;
2803 return remainder(x, y);
2804 #else
2805 FIXME( "not implemented\n" );
2806 return 0.0;
2807 #endif
2810 /*********************************************************************
2811 * remainderf (MSVCR120.@)
2813 float CDECL MSVCR120_remainderf(float x, float y)
2815 #ifdef HAVE_REMAINDERF
2816 /* this matches 64-bit Windows. 32-bit Windows is slightly different */
2817 if(!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
2818 if(isnanf(y) || y==0.0f) *MSVCRT__errno() = MSVCRT_EDOM;
2819 return remainderf(x, y);
2820 #else
2821 FIXME( "not implemented\n" );
2822 return 0.0f;
2823 #endif
2826 /*********************************************************************
2827 * remainderl (MSVCR120.@)
2829 LDOUBLE CDECL MSVCR120_remainderl(LDOUBLE x, LDOUBLE y)
2831 return MSVCR120_remainder(x, y);