msvcr120: Add asinh.
[wine.git] / dlls / msvcrt / math.c
blob4150cfc99906e70bbd5190872c432b463afc388a
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 * _scalbf (MSVCRT.@)
336 float CDECL MSVCRT__scalbf(float num, MSVCRT_long power)
338 if (!finitef(num)) *MSVCRT__errno() = MSVCRT_EDOM;
339 return ldexpf(num, power);
342 /*********************************************************************
343 * modff (MSVCRT.@)
345 float CDECL MSVCRT_modff( float x, float *iptr )
347 return modff( x, iptr );
350 #endif
352 /*********************************************************************
353 * MSVCRT_acos (MSVCRT.@)
355 double CDECL MSVCRT_acos( double x )
357 if (x < -1.0 || x > 1.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
358 /* glibc implements acos() as the FPU equivalent of atan2(sqrt(1 - x ^ 2), x).
359 * asin() uses a similar construction. This is bad because as x gets nearer to
360 * 1 the error in the expression "1 - x^2" can get relatively large due to
361 * cancellation. The sqrt() makes things worse. A safer way to calculate
362 * acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */
363 return atan2(sqrt((1 - x) * (1 + x)), x);
366 /*********************************************************************
367 * MSVCRT_asin (MSVCRT.@)
369 double CDECL MSVCRT_asin( double x )
371 if (x < -1.0 || x > 1.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
372 return atan2(x, sqrt((1 - x) * (1 + x)));
375 /*********************************************************************
376 * MSVCRT_atan (MSVCRT.@)
378 double CDECL MSVCRT_atan( double x )
380 if (isnan(x)) *MSVCRT__errno() = MSVCRT_EDOM;
381 return atan(x);
384 /*********************************************************************
385 * MSVCRT_atan2 (MSVCRT.@)
387 double CDECL MSVCRT_atan2( double x, double y )
389 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
390 return atan2(x,y);
393 /*********************************************************************
394 * MSVCRT_cos (MSVCRT.@)
396 double CDECL MSVCRT_cos( double x )
398 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
399 return cos(x);
402 /*********************************************************************
403 * MSVCRT_cosh (MSVCRT.@)
405 double CDECL MSVCRT_cosh( double x )
407 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
408 return cosh(x);
411 /*********************************************************************
412 * MSVCRT_exp (MSVCRT.@)
414 double CDECL MSVCRT_exp( double x )
416 if (isnan(x)) *MSVCRT__errno() = MSVCRT_EDOM;
417 return exp(x);
420 /*********************************************************************
421 * MSVCRT_fmod (MSVCRT.@)
423 double CDECL MSVCRT_fmod( double x, double y )
425 if (!isfinite(x) || !isfinite(y)) *MSVCRT__errno() = MSVCRT_EDOM;
426 return fmod(x,y);
429 /*********************************************************************
430 * MSVCRT_log (MSVCRT.@)
432 double CDECL MSVCRT_log( double x)
434 if (x < 0.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
435 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
436 return log(x);
439 /*********************************************************************
440 * MSVCRT_log10 (MSVCRT.@)
442 double CDECL MSVCRT_log10( double x )
444 if (x < 0.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
445 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
446 return log10(x);
449 /*********************************************************************
450 * MSVCRT_pow (MSVCRT.@)
452 double CDECL MSVCRT_pow( double x, double y )
454 /* FIXME: If x < 0 and y is not integral, set EDOM */
455 double z = pow(x,y);
456 if (!isfinite(z)) *MSVCRT__errno() = MSVCRT_EDOM;
457 return z;
460 /*********************************************************************
461 * MSVCRT_sin (MSVCRT.@)
463 double CDECL MSVCRT_sin( double x )
465 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
466 return sin(x);
469 /*********************************************************************
470 * MSVCRT_sinh (MSVCRT.@)
472 double CDECL MSVCRT_sinh( double x )
474 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
475 return sinh(x);
478 /*********************************************************************
479 * MSVCRT_sqrt (MSVCRT.@)
481 double CDECL MSVCRT_sqrt( double x )
483 if (x < 0.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
484 return sqrt(x);
487 /*********************************************************************
488 * MSVCRT_tan (MSVCRT.@)
490 double CDECL MSVCRT_tan( double x )
492 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
493 return tan(x);
496 /*********************************************************************
497 * MSVCRT_tanh (MSVCRT.@)
499 double CDECL MSVCRT_tanh( double x )
501 if (isnan(x)) *MSVCRT__errno() = MSVCRT_EDOM;
502 return tanh(x);
506 #if defined(__GNUC__) && defined(__i386__)
508 #define FPU_DOUBLE(var) double var; \
509 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
510 #define FPU_DOUBLES(var1,var2) double var1,var2; \
511 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
512 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
514 /*********************************************************************
515 * _CIacos (MSVCRT.@)
517 double CDECL _CIacos(void)
519 FPU_DOUBLE(x);
520 return MSVCRT_acos(x);
523 /*********************************************************************
524 * _CIasin (MSVCRT.@)
526 double CDECL _CIasin(void)
528 FPU_DOUBLE(x);
529 return MSVCRT_asin(x);
532 /*********************************************************************
533 * _CIatan (MSVCRT.@)
535 double CDECL _CIatan(void)
537 FPU_DOUBLE(x);
538 return MSVCRT_atan(x);
541 /*********************************************************************
542 * _CIatan2 (MSVCRT.@)
544 double CDECL _CIatan2(void)
546 FPU_DOUBLES(x,y);
547 return MSVCRT_atan2(x,y);
550 /*********************************************************************
551 * _CIcos (MSVCRT.@)
553 double CDECL _CIcos(void)
555 FPU_DOUBLE(x);
556 return MSVCRT_cos(x);
559 /*********************************************************************
560 * _CIcosh (MSVCRT.@)
562 double CDECL _CIcosh(void)
564 FPU_DOUBLE(x);
565 return MSVCRT_cosh(x);
568 /*********************************************************************
569 * _CIexp (MSVCRT.@)
571 double CDECL _CIexp(void)
573 FPU_DOUBLE(x);
574 return MSVCRT_exp(x);
577 /*********************************************************************
578 * _CIfmod (MSVCRT.@)
580 double CDECL _CIfmod(void)
582 FPU_DOUBLES(x,y);
583 return MSVCRT_fmod(x,y);
586 /*********************************************************************
587 * _CIlog (MSVCRT.@)
589 double CDECL _CIlog(void)
591 FPU_DOUBLE(x);
592 return MSVCRT_log(x);
595 /*********************************************************************
596 * _CIlog10 (MSVCRT.@)
598 double CDECL _CIlog10(void)
600 FPU_DOUBLE(x);
601 return MSVCRT_log10(x);
604 /*********************************************************************
605 * _CIpow (MSVCRT.@)
607 double CDECL _CIpow(void)
609 FPU_DOUBLES(x,y);
610 return MSVCRT_pow(x,y);
613 /*********************************************************************
614 * _CIsin (MSVCRT.@)
616 double CDECL _CIsin(void)
618 FPU_DOUBLE(x);
619 return MSVCRT_sin(x);
622 /*********************************************************************
623 * _CIsinh (MSVCRT.@)
625 double CDECL _CIsinh(void)
627 FPU_DOUBLE(x);
628 return MSVCRT_sinh(x);
631 /*********************************************************************
632 * _CIsqrt (MSVCRT.@)
634 double CDECL _CIsqrt(void)
636 FPU_DOUBLE(x);
637 return MSVCRT_sqrt(x);
640 /*********************************************************************
641 * _CItan (MSVCRT.@)
643 double CDECL _CItan(void)
645 FPU_DOUBLE(x);
646 return MSVCRT_tan(x);
649 /*********************************************************************
650 * _CItanh (MSVCRT.@)
652 double CDECL _CItanh(void)
654 FPU_DOUBLE(x);
655 return MSVCRT_tanh(x);
658 /*********************************************************************
659 * _ftol (MSVCRT.@)
661 LONGLONG CDECL MSVCRT__ftol(void)
663 FPU_DOUBLE(x);
664 return (LONGLONG)x;
667 #endif /* defined(__GNUC__) && defined(__i386__) */
669 /*********************************************************************
670 * _fpclass (MSVCRT.@)
672 int CDECL MSVCRT__fpclass(double num)
674 #if defined(HAVE_FPCLASS) || defined(fpclass)
675 switch (fpclass( num ))
677 #ifdef FP_SNAN
678 case FP_SNAN: return MSVCRT__FPCLASS_SNAN;
679 #endif
680 #ifdef FP_QNAN
681 case FP_QNAN: return MSVCRT__FPCLASS_QNAN;
682 #endif
683 #ifdef FP_NINF
684 case FP_NINF: return MSVCRT__FPCLASS_NINF;
685 #endif
686 #ifdef FP_PINF
687 case FP_PINF: return MSVCRT__FPCLASS_PINF;
688 #endif
689 #ifdef FP_NDENORM
690 case FP_NDENORM: return MSVCRT__FPCLASS_ND;
691 #endif
692 #ifdef FP_PDENORM
693 case FP_PDENORM: return MSVCRT__FPCLASS_PD;
694 #endif
695 #ifdef FP_NZERO
696 case FP_NZERO: return MSVCRT__FPCLASS_NZ;
697 #endif
698 #ifdef FP_PZERO
699 case FP_PZERO: return MSVCRT__FPCLASS_PZ;
700 #endif
701 #ifdef FP_NNORM
702 case FP_NNORM: return MSVCRT__FPCLASS_NN;
703 #endif
704 #ifdef FP_PNORM
705 case FP_PNORM: return MSVCRT__FPCLASS_PN;
706 #endif
707 default: return MSVCRT__FPCLASS_PN;
709 #elif defined (fpclassify)
710 switch (fpclassify( num ))
712 case FP_NAN: return MSVCRT__FPCLASS_QNAN;
713 case FP_INFINITE: return signbit(num) ? MSVCRT__FPCLASS_NINF : MSVCRT__FPCLASS_PINF;
714 case FP_SUBNORMAL: return signbit(num) ?MSVCRT__FPCLASS_ND : MSVCRT__FPCLASS_PD;
715 case FP_ZERO: return signbit(num) ? MSVCRT__FPCLASS_NZ : MSVCRT__FPCLASS_PZ;
717 return signbit(num) ? MSVCRT__FPCLASS_NN : MSVCRT__FPCLASS_PN;
718 #else
719 if (!isfinite(num))
720 return MSVCRT__FPCLASS_QNAN;
721 return num == 0.0 ? MSVCRT__FPCLASS_PZ : (num < 0 ? MSVCRT__FPCLASS_NN : MSVCRT__FPCLASS_PN);
722 #endif
725 /*********************************************************************
726 * _rotl (MSVCRT.@)
728 unsigned int CDECL _rotl(unsigned int num, int shift)
730 shift &= 31;
731 return (num << shift) | (num >> (32-shift));
734 /*********************************************************************
735 * _lrotl (MSVCRT.@)
737 MSVCRT_ulong CDECL MSVCRT__lrotl(MSVCRT_ulong num, int shift)
739 shift &= 0x1f;
740 return (num << shift) | (num >> (32-shift));
743 /*********************************************************************
744 * _lrotr (MSVCRT.@)
746 MSVCRT_ulong CDECL MSVCRT__lrotr(MSVCRT_ulong num, int shift)
748 shift &= 0x1f;
749 return (num >> shift) | (num << (32-shift));
752 /*********************************************************************
753 * _rotr (MSVCRT.@)
755 unsigned int CDECL _rotr(unsigned int num, int shift)
757 shift &= 0x1f;
758 return (num >> shift) | (num << (32-shift));
761 /*********************************************************************
762 * _rotl64 (MSVCRT.@)
764 unsigned __int64 CDECL _rotl64(unsigned __int64 num, int shift)
766 shift &= 63;
767 return (num << shift) | (num >> (64-shift));
770 /*********************************************************************
771 * _rotr64 (MSVCRT.@)
773 unsigned __int64 CDECL _rotr64(unsigned __int64 num, int shift)
775 shift &= 63;
776 return (num >> shift) | (num << (64-shift));
779 /*********************************************************************
780 * abs (MSVCRT.@)
782 int CDECL MSVCRT_abs( int n )
784 return n >= 0 ? n : -n;
787 /*********************************************************************
788 * labs (MSVCRT.@)
790 MSVCRT_long CDECL MSVCRT_labs( MSVCRT_long n )
792 return n >= 0 ? n : -n;
795 /*********************************************************************
796 * llabs (MSVCRT.@)
798 MSVCRT_longlong CDECL MSVCRT_llabs( MSVCRT_longlong n )
800 return n >= 0 ? n : -n;
803 /*********************************************************************
804 * _abs64 (MSVCRT.@)
806 __int64 CDECL _abs64( __int64 n )
808 return n >= 0 ? n : -n;
811 /*********************************************************************
812 * _logb (MSVCRT.@)
814 double CDECL MSVCRT__logb(double num)
816 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
817 return logb(num);
820 /*********************************************************************
821 * _scalb (MSVCRT.@)
823 double CDECL MSVCRT__scalb(double num, MSVCRT_long power)
825 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
826 return ldexp(num, power);
829 /*********************************************************************
830 * _hypot (MSVCRT.@)
832 double CDECL _hypot(double x, double y)
834 /* FIXME: errno handling */
835 return hypot( x, y );
838 /*********************************************************************
839 * _hypotf (MSVCRT.@)
841 float CDECL MSVCRT__hypotf(float x, float y)
843 /* FIXME: errno handling */
844 return hypotf( x, y );
847 /*********************************************************************
848 * ceil (MSVCRT.@)
850 double CDECL MSVCRT_ceil( double x )
852 return ceil(x);
855 /*********************************************************************
856 * floor (MSVCRT.@)
858 double CDECL MSVCRT_floor( double x )
860 return floor(x);
863 /*********************************************************************
864 * fabs (MSVCRT.@)
866 double CDECL MSVCRT_fabs( double x )
868 return fabs(x);
871 /*********************************************************************
872 * frexp (MSVCRT.@)
874 double CDECL MSVCRT_frexp( double x, int *exp )
876 return frexp( x, exp );
879 /*********************************************************************
880 * modf (MSVCRT.@)
882 double CDECL MSVCRT_modf( double x, double *iptr )
884 return modf( x, iptr );
887 /*********************************************************************
888 * _matherr (MSVCRT.@)
890 int CDECL MSVCRT__matherr(struct MSVCRT__exception *e)
892 if (e)
893 TRACE("(%p = %d, %s, %g %g %g)\n",e, e->type, e->name, e->arg1, e->arg2,
894 e->retval);
895 else
896 TRACE("(null)\n");
897 if (MSVCRT_default_matherr_func)
898 return MSVCRT_default_matherr_func(e);
899 ERR(":Unhandled math error!\n");
900 return 0;
903 /*********************************************************************
904 * __setusermatherr (MSVCRT.@)
906 void CDECL MSVCRT___setusermatherr(MSVCRT_matherr_func func)
908 MSVCRT_default_matherr_func = func;
909 TRACE(":new matherr handler %p\n", func);
912 /**********************************************************************
913 * _statusfp2 (MSVCRT.@)
915 * Not exported by native msvcrt, added in msvcr80.
917 #if defined(__i386__) || defined(__x86_64__)
918 void CDECL _statusfp2( unsigned int *x86_sw, unsigned int *sse2_sw )
920 #ifdef __GNUC__
921 unsigned int flags;
922 unsigned long fpword;
924 if (x86_sw)
926 __asm__ __volatile__( "fstsw %0" : "=m" (fpword) );
927 flags = 0;
928 if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
929 if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
930 if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
931 if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
932 if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
933 if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
934 *x86_sw = flags;
937 if (!sse2_sw) return;
939 if (sse2_supported)
941 __asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
942 flags = 0;
943 if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
944 if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
945 if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
946 if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
947 if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
948 if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
949 *sse2_sw = flags;
951 else *sse2_sw = 0;
952 #else
953 FIXME( "not implemented\n" );
954 #endif
956 #endif
958 /**********************************************************************
959 * _statusfp (MSVCRT.@)
961 unsigned int CDECL _statusfp(void)
963 #if defined(__i386__) || defined(__x86_64__)
964 unsigned int x86_sw, sse2_sw;
966 _statusfp2( &x86_sw, &sse2_sw );
967 /* FIXME: there's no definition for ambiguous status, just return all status bits for now */
968 return x86_sw | sse2_sw;
969 #else
970 FIXME( "not implemented\n" );
971 return 0;
972 #endif
975 /*********************************************************************
976 * _clearfp (MSVCRT.@)
978 unsigned int CDECL _clearfp(void)
980 unsigned int flags = 0;
981 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
982 unsigned long fpword;
984 __asm__ __volatile__( "fnstsw %0; fnclex" : "=m" (fpword) );
985 if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
986 if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
987 if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
988 if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
989 if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
990 if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
992 if (sse2_supported)
994 __asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
995 if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
996 if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
997 if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
998 if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
999 if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
1000 if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
1001 fpword &= ~0x3f;
1002 __asm__ __volatile__( "ldmxcsr %0" : : "m" (fpword) );
1004 #else
1005 FIXME( "not implemented\n" );
1006 #endif
1007 return flags;
1010 /*********************************************************************
1011 * __fpecode (MSVCRT.@)
1013 int * CDECL __fpecode(void)
1015 return &msvcrt_get_thread_data()->fpecode;
1018 /*********************************************************************
1019 * ldexp (MSVCRT.@)
1021 double CDECL MSVCRT_ldexp(double num, MSVCRT_long exp)
1023 double z = ldexp(num,exp);
1025 if (!isfinite(z))
1026 *MSVCRT__errno() = MSVCRT_ERANGE;
1027 else if (z == 0 && signbit(z))
1028 z = 0.0; /* Convert -0 -> +0 */
1029 return z;
1032 /*********************************************************************
1033 * _cabs (MSVCRT.@)
1035 double CDECL MSVCRT__cabs(struct MSVCRT__complex num)
1037 return sqrt(num.x * num.x + num.y * num.y);
1040 /*********************************************************************
1041 * _chgsign (MSVCRT.@)
1043 double CDECL MSVCRT__chgsign(double num)
1045 /* FIXME: +-infinity,Nan not tested */
1046 return -num;
1049 /*********************************************************************
1050 * __control87_2 (MSVCRT.@)
1052 * Not exported by native msvcrt, added in msvcr80.
1054 #if defined(__i386__) || defined(__x86_64__)
1055 int CDECL __control87_2( unsigned int newval, unsigned int mask,
1056 unsigned int *x86_cw, unsigned int *sse2_cw )
1058 #ifdef __GNUC__
1059 unsigned long fpword;
1060 unsigned int flags;
1062 if (x86_cw)
1064 __asm__ __volatile__( "fstcw %0" : "=m" (fpword) );
1066 /* Convert into mask constants */
1067 flags = 0;
1068 if (fpword & 0x1) flags |= MSVCRT__EM_INVALID;
1069 if (fpword & 0x2) flags |= MSVCRT__EM_DENORMAL;
1070 if (fpword & 0x4) flags |= MSVCRT__EM_ZERODIVIDE;
1071 if (fpword & 0x8) flags |= MSVCRT__EM_OVERFLOW;
1072 if (fpword & 0x10) flags |= MSVCRT__EM_UNDERFLOW;
1073 if (fpword & 0x20) flags |= MSVCRT__EM_INEXACT;
1074 switch (fpword & 0xc00)
1076 case 0xc00: flags |= MSVCRT__RC_UP|MSVCRT__RC_DOWN; break;
1077 case 0x800: flags |= MSVCRT__RC_UP; break;
1078 case 0x400: flags |= MSVCRT__RC_DOWN; break;
1080 switch (fpword & 0x300)
1082 case 0x0: flags |= MSVCRT__PC_24; break;
1083 case 0x200: flags |= MSVCRT__PC_53; break;
1084 case 0x300: flags |= MSVCRT__PC_64; break;
1086 if (fpword & 0x1000) flags |= MSVCRT__IC_AFFINE;
1088 TRACE( "x86 flags=%08x newval=%08x mask=%08x\n", flags, newval, mask );
1089 if (mask)
1091 flags = (flags & ~mask) | (newval & mask);
1093 /* Convert (masked) value back to fp word */
1094 fpword = 0;
1095 if (flags & MSVCRT__EM_INVALID) fpword |= 0x1;
1096 if (flags & MSVCRT__EM_DENORMAL) fpword |= 0x2;
1097 if (flags & MSVCRT__EM_ZERODIVIDE) fpword |= 0x4;
1098 if (flags & MSVCRT__EM_OVERFLOW) fpword |= 0x8;
1099 if (flags & MSVCRT__EM_UNDERFLOW) fpword |= 0x10;
1100 if (flags & MSVCRT__EM_INEXACT) fpword |= 0x20;
1101 switch (flags & MSVCRT__MCW_RC)
1103 case MSVCRT__RC_UP|MSVCRT__RC_DOWN: fpword |= 0xc00; break;
1104 case MSVCRT__RC_UP: fpword |= 0x800; break;
1105 case MSVCRT__RC_DOWN: fpword |= 0x400; break;
1107 switch (flags & MSVCRT__MCW_PC)
1109 case MSVCRT__PC_64: fpword |= 0x300; break;
1110 case MSVCRT__PC_53: fpword |= 0x200; break;
1111 case MSVCRT__PC_24: fpword |= 0x0; break;
1113 if (flags & MSVCRT__IC_AFFINE) fpword |= 0x1000;
1115 __asm__ __volatile__( "fldcw %0" : : "m" (fpword) );
1117 *x86_cw = flags;
1120 if (!sse2_cw) return 1;
1122 if (sse2_supported)
1124 __asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
1126 /* Convert into mask constants */
1127 flags = 0;
1128 if (fpword & 0x80) flags |= MSVCRT__EM_INVALID;
1129 if (fpword & 0x100) flags |= MSVCRT__EM_DENORMAL;
1130 if (fpword & 0x200) flags |= MSVCRT__EM_ZERODIVIDE;
1131 if (fpword & 0x400) flags |= MSVCRT__EM_OVERFLOW;
1132 if (fpword & 0x800) flags |= MSVCRT__EM_UNDERFLOW;
1133 if (fpword & 0x1000) flags |= MSVCRT__EM_INEXACT;
1134 switch (fpword & 0x6000)
1136 case 0x6000: flags |= MSVCRT__RC_UP|MSVCRT__RC_DOWN; break;
1137 case 0x4000: flags |= MSVCRT__RC_UP; break;
1138 case 0x2000: flags |= MSVCRT__RC_DOWN; break;
1140 switch (fpword & 0x8040)
1142 case 0x0040: flags |= MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS; break;
1143 case 0x8000: flags |= MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS; break;
1144 case 0x8040: flags |= MSVCRT__DN_FLUSH; break;
1147 TRACE( "sse2 flags=%08x newval=%08x mask=%08x\n", flags, newval, mask );
1148 if (mask)
1150 flags = (flags & ~mask) | (newval & mask);
1152 /* Convert (masked) value back to fp word */
1153 fpword = 0;
1154 if (flags & MSVCRT__EM_INVALID) fpword |= 0x80;
1155 if (flags & MSVCRT__EM_DENORMAL) fpword |= 0x100;
1156 if (flags & MSVCRT__EM_ZERODIVIDE) fpword |= 0x200;
1157 if (flags & MSVCRT__EM_OVERFLOW) fpword |= 0x400;
1158 if (flags & MSVCRT__EM_UNDERFLOW) fpword |= 0x800;
1159 if (flags & MSVCRT__EM_INEXACT) fpword |= 0x1000;
1160 switch (flags & MSVCRT__MCW_RC)
1162 case MSVCRT__RC_UP|MSVCRT__RC_DOWN: fpword |= 0x6000; break;
1163 case MSVCRT__RC_UP: fpword |= 0x4000; break;
1164 case MSVCRT__RC_DOWN: fpword |= 0x2000; break;
1166 switch (flags & MSVCRT__MCW_DN)
1168 case MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS: fpword |= 0x0040; break;
1169 case MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS: fpword |= 0x8000; break;
1170 case MSVCRT__DN_FLUSH: fpword |= 0x8040; break;
1172 __asm__ __volatile__( "ldmxcsr %0" : : "m" (fpword) );
1174 *sse2_cw = flags;
1176 else *sse2_cw = 0;
1178 return 1;
1179 #else
1180 FIXME( "not implemented\n" );
1181 return 0;
1182 #endif
1184 #endif
1186 /*********************************************************************
1187 * _control87 (MSVCRT.@)
1189 unsigned int CDECL _control87(unsigned int newval, unsigned int mask)
1191 #if defined(__i386__) || defined(__x86_64__)
1192 unsigned int x86_cw, sse2_cw;
1194 __control87_2( newval, mask, &x86_cw, &sse2_cw );
1196 if ((x86_cw ^ sse2_cw) & (MSVCRT__MCW_EM | MSVCRT__MCW_RC)) x86_cw |= MSVCRT__EM_AMBIGUOUS;
1197 return x86_cw;
1198 #else
1199 FIXME( "not implemented\n" );
1200 return 0;
1201 #endif
1204 /*********************************************************************
1205 * _controlfp (MSVCRT.@)
1207 unsigned int CDECL _controlfp(unsigned int newval, unsigned int mask)
1209 return _control87( newval, mask & ~MSVCRT__EM_DENORMAL );
1212 /*********************************************************************
1213 * _set_controlfp (MSVCRT.@)
1215 void CDECL _set_controlfp( unsigned int newval, unsigned int mask )
1217 _controlfp( newval, mask );
1220 /*********************************************************************
1221 * _controlfp_s (MSVCRT.@)
1223 int CDECL _controlfp_s(unsigned int *cur, unsigned int newval, unsigned int mask)
1225 static const unsigned int all_flags = (MSVCRT__MCW_EM | MSVCRT__MCW_IC | MSVCRT__MCW_RC |
1226 MSVCRT__MCW_PC | MSVCRT__MCW_DN);
1227 unsigned int val;
1229 if (!MSVCRT_CHECK_PMT( !(newval & mask & ~all_flags) ))
1231 if (cur) *cur = _controlfp( 0, 0 ); /* retrieve it anyway */
1232 return MSVCRT_EINVAL;
1234 val = _controlfp( newval, mask );
1235 if (cur) *cur = val;
1236 return 0;
1239 /*********************************************************************
1240 * _copysign (MSVCRT.@)
1242 double CDECL MSVCRT__copysign(double num, double sign)
1244 if (signbit(sign))
1245 return signbit(num) ? num : -num;
1246 return signbit(num) ? -num : num;
1249 /*********************************************************************
1250 * _finite (MSVCRT.@)
1252 int CDECL MSVCRT__finite(double num)
1254 return isfinite(num) != 0; /* See comment for _isnan() */
1257 /*********************************************************************
1258 * _fpreset (MSVCRT.@)
1260 void CDECL _fpreset(void)
1262 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1263 const unsigned int x86_cw = 0x27f;
1264 __asm__ __volatile__( "fninit; fldcw %0" : : "m" (x86_cw) );
1265 if (sse2_supported)
1267 const unsigned long sse2_cw = 0x1f80;
1268 __asm__ __volatile__( "ldmxcsr %0" : : "m" (sse2_cw) );
1270 #else
1271 FIXME( "not implemented\n" );
1272 #endif
1275 /*********************************************************************
1276 * _isnan (MSVCRT.@)
1278 INT CDECL MSVCRT__isnan(double num)
1280 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
1281 * Do the same, as the result may be used in calculations
1283 return isnan(num) != 0;
1286 /*********************************************************************
1287 * _j0 (MSVCRT.@)
1289 double CDECL MSVCRT__j0(double num)
1291 /* FIXME: errno handling */
1292 return j0(num);
1295 /*********************************************************************
1296 * _j1 (MSVCRT.@)
1298 double CDECL MSVCRT__j1(double num)
1300 /* FIXME: errno handling */
1301 return j1(num);
1304 /*********************************************************************
1305 * _jn (MSVCRT.@)
1307 double CDECL MSVCRT__jn(int n, double num)
1309 /* FIXME: errno handling */
1310 return jn(n, num);
1313 /*********************************************************************
1314 * _y0 (MSVCRT.@)
1316 double CDECL MSVCRT__y0(double num)
1318 double retval;
1319 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
1320 retval = y0(num);
1321 if (MSVCRT__fpclass(retval) == MSVCRT__FPCLASS_NINF)
1323 *MSVCRT__errno() = MSVCRT_EDOM;
1324 retval = sqrt(-1);
1326 return retval;
1329 /*********************************************************************
1330 * _y1 (MSVCRT.@)
1332 double CDECL MSVCRT__y1(double num)
1334 double retval;
1335 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
1336 retval = y1(num);
1337 if (MSVCRT__fpclass(retval) == MSVCRT__FPCLASS_NINF)
1339 *MSVCRT__errno() = MSVCRT_EDOM;
1340 retval = sqrt(-1);
1342 return retval;
1345 /*********************************************************************
1346 * _yn (MSVCRT.@)
1348 double CDECL MSVCRT__yn(int order, double num)
1350 double retval;
1351 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
1352 retval = yn(order,num);
1353 if (MSVCRT__fpclass(retval) == MSVCRT__FPCLASS_NINF)
1355 *MSVCRT__errno() = MSVCRT_EDOM;
1356 retval = sqrt(-1);
1358 return retval;
1361 /*********************************************************************
1362 * _nextafter (MSVCRT.@)
1364 double CDECL MSVCRT__nextafter(double num, double next)
1366 double retval;
1367 if (!isfinite(num) || !isfinite(next)) *MSVCRT__errno() = MSVCRT_EDOM;
1368 retval = nextafter(num,next);
1369 return retval;
1372 /*********************************************************************
1373 * _ecvt (MSVCRT.@)
1375 char * CDECL MSVCRT__ecvt( double number, int ndigits, int *decpt, int *sign )
1377 int prec, len;
1378 thread_data_t *data = msvcrt_get_thread_data();
1379 /* FIXME: check better for overflow (native supports over 300 chars) */
1380 ndigits = min( ndigits, 80 - 7); /* 7 : space for dec point, 1 for "e",
1381 * 4 for exponent and one for
1382 * terminating '\0' */
1383 if (!data->efcvt_buffer)
1384 data->efcvt_buffer = MSVCRT_malloc( 80 ); /* ought to be enough */
1386 if( number < 0) {
1387 *sign = TRUE;
1388 number = -number;
1389 } else
1390 *sign = FALSE;
1391 /* handle cases with zero ndigits or less */
1392 prec = ndigits;
1393 if( prec < 1) prec = 2;
1394 len = snprintf(data->efcvt_buffer, 80, "%.*le", prec - 1, number);
1395 /* take the decimal "point away */
1396 if( prec != 1)
1397 memmove( data->efcvt_buffer + 1, data->efcvt_buffer + 2, len - 1 );
1398 /* take the exponential "e" out */
1399 data->efcvt_buffer[ prec] = '\0';
1400 /* read the exponent */
1401 sscanf( data->efcvt_buffer + prec + 1, "%d", decpt);
1402 (*decpt)++;
1403 /* adjust for some border cases */
1404 if( data->efcvt_buffer[0] == '0')/* value is zero */
1405 *decpt = 0;
1406 /* handle cases with zero ndigits or less */
1407 if( ndigits < 1){
1408 if( data->efcvt_buffer[ 0] >= '5')
1409 (*decpt)++;
1410 data->efcvt_buffer[ 0] = '\0';
1412 TRACE("out=\"%s\"\n",data->efcvt_buffer);
1413 return data->efcvt_buffer;
1416 /*********************************************************************
1417 * _ecvt_s (MSVCRT.@)
1419 int CDECL MSVCRT__ecvt_s( char *buffer, MSVCRT_size_t length, double number, int ndigits, int *decpt, int *sign )
1421 int prec, len;
1422 char *result;
1423 const char infret[] = "1#INF";
1425 if (!MSVCRT_CHECK_PMT(buffer != NULL)) return MSVCRT_EINVAL;
1426 if (!MSVCRT_CHECK_PMT(decpt != NULL)) return MSVCRT_EINVAL;
1427 if (!MSVCRT_CHECK_PMT(sign != NULL)) return MSVCRT_EINVAL;
1428 if (!MSVCRT_CHECK_PMT_ERR( length > 2, MSVCRT_ERANGE )) return MSVCRT_ERANGE;
1429 if (!MSVCRT_CHECK_PMT_ERR(ndigits < (int)length - 1, MSVCRT_ERANGE )) return MSVCRT_ERANGE;
1431 /* special case - inf */
1432 if(number == HUGE_VAL || number == -HUGE_VAL)
1434 memset(buffer, '0', ndigits);
1435 memcpy(buffer, infret, min(ndigits, sizeof(infret) - 1 ) );
1436 buffer[ndigits] = '\0';
1437 (*decpt) = 1;
1438 if(number == -HUGE_VAL)
1439 (*sign) = 1;
1440 else
1441 (*sign) = 0;
1442 return 0;
1444 /* handle cases with zero ndigits or less */
1445 prec = ndigits;
1446 if( prec < 1) prec = 2;
1447 result = MSVCRT_malloc(prec + 7);
1449 if( number < 0) {
1450 *sign = TRUE;
1451 number = -number;
1452 } else
1453 *sign = FALSE;
1454 len = snprintf(result, prec + 7, "%.*le", prec - 1, number);
1455 /* take the decimal "point away */
1456 if( prec != 1)
1457 memmove( result + 1, result + 2, len - 1 );
1458 /* take the exponential "e" out */
1459 result[ prec] = '\0';
1460 /* read the exponent */
1461 sscanf( result + prec + 1, "%d", decpt);
1462 (*decpt)++;
1463 /* adjust for some border cases */
1464 if( result[0] == '0')/* value is zero */
1465 *decpt = 0;
1466 /* handle cases with zero ndigits or less */
1467 if( ndigits < 1){
1468 if( result[ 0] >= '5')
1469 (*decpt)++;
1470 result[ 0] = '\0';
1472 memcpy( buffer, result, max(ndigits + 1, 1) );
1473 MSVCRT_free( result );
1474 return 0;
1477 /***********************************************************************
1478 * _fcvt (MSVCRT.@)
1480 char * CDECL MSVCRT__fcvt( double number, int ndigits, int *decpt, int *sign )
1482 thread_data_t *data = msvcrt_get_thread_data();
1483 int stop, dec1, dec2;
1484 char *ptr1, *ptr2, *first;
1485 char buf[80]; /* ought to be enough */
1487 if (!data->efcvt_buffer)
1488 data->efcvt_buffer = MSVCRT_malloc( 80 ); /* ought to be enough */
1490 if (number < 0)
1492 *sign = 1;
1493 number = -number;
1494 } else *sign = 0;
1496 snprintf(buf, 80, "%.*f", ndigits < 0 ? 0 : ndigits, number);
1497 ptr1 = buf;
1498 ptr2 = data->efcvt_buffer;
1499 first = NULL;
1500 dec1 = 0;
1501 dec2 = 0;
1503 /* For numbers below the requested resolution, work out where
1504 the decimal point will be rather than finding it in the string */
1505 if (number < 1.0 && number > 0.0) {
1506 dec2 = log10(number + 1e-10);
1507 if (-dec2 <= ndigits) dec2 = 0;
1510 /* If requested digits is zero or less, we will need to truncate
1511 * the returned string */
1512 if (ndigits < 1) {
1513 stop = strlen(buf) + ndigits;
1514 } else {
1515 stop = strlen(buf);
1518 while (*ptr1 == '0') ptr1++; /* Skip leading zeroes */
1519 while (*ptr1 != '\0' && *ptr1 != '.') {
1520 if (!first) first = ptr2;
1521 if ((ptr1 - buf) < stop) {
1522 *ptr2++ = *ptr1++;
1523 } else {
1524 ptr1++;
1526 dec1++;
1529 if (ndigits > 0) {
1530 ptr1++;
1531 if (!first) {
1532 while (*ptr1 == '0') { /* Process leading zeroes */
1533 *ptr2++ = *ptr1++;
1534 dec1--;
1537 while (*ptr1 != '\0') {
1538 if (!first) first = ptr2;
1539 *ptr2++ = *ptr1++;
1543 *ptr2 = '\0';
1545 /* We never found a non-zero digit, then our number is either
1546 * smaller than the requested precision, or 0.0 */
1547 if (!first) {
1548 if (number > 0.0) {
1549 first = ptr2;
1550 } else {
1551 first = data->efcvt_buffer;
1552 dec1 = 0;
1556 *decpt = dec2 ? dec2 : dec1;
1557 return first;
1560 /***********************************************************************
1561 * _fcvt_s (MSVCRT.@)
1563 int CDECL MSVCRT__fcvt_s(char* outbuffer, MSVCRT_size_t size, double number, int ndigits, int *decpt, int *sign)
1565 int stop, dec1, dec2;
1566 char *ptr1, *ptr2, *first;
1567 char buf[80]; /* ought to be enough */
1569 if (!outbuffer || !decpt || !sign || size == 0)
1571 *MSVCRT__errno() = MSVCRT_EINVAL;
1572 return MSVCRT_EINVAL;
1575 if (number < 0)
1577 *sign = 1;
1578 number = -number;
1579 } else *sign = 0;
1581 snprintf(buf, 80, "%.*f", ndigits < 0 ? 0 : ndigits, number);
1582 ptr1 = buf;
1583 ptr2 = outbuffer;
1584 first = NULL;
1585 dec1 = 0;
1586 dec2 = 0;
1588 /* For numbers below the requested resolution, work out where
1589 the decimal point will be rather than finding it in the string */
1590 if (number < 1.0 && number > 0.0) {
1591 dec2 = log10(number + 1e-10);
1592 if (-dec2 <= ndigits) dec2 = 0;
1595 /* If requested digits is zero or less, we will need to truncate
1596 * the returned string */
1597 if (ndigits < 1) {
1598 stop = strlen(buf) + ndigits;
1599 } else {
1600 stop = strlen(buf);
1603 while (*ptr1 == '0') ptr1++; /* Skip leading zeroes */
1604 while (*ptr1 != '\0' && *ptr1 != '.') {
1605 if (!first) first = ptr2;
1606 if ((ptr1 - buf) < stop) {
1607 if (size > 1) {
1608 *ptr2++ = *ptr1++;
1609 size--;
1611 } else {
1612 ptr1++;
1614 dec1++;
1617 if (ndigits > 0) {
1618 ptr1++;
1619 if (!first) {
1620 while (*ptr1 == '0') { /* Process leading zeroes */
1621 if (number == 0.0 && size > 1) {
1622 *ptr2++ = '0';
1623 size--;
1625 ptr1++;
1626 dec1--;
1629 while (*ptr1 != '\0') {
1630 if (!first) first = ptr2;
1631 if (size > 1) {
1632 *ptr2++ = *ptr1++;
1633 size--;
1638 *ptr2 = '\0';
1640 /* We never found a non-zero digit, then our number is either
1641 * smaller than the requested precision, or 0.0 */
1642 if (!first && (number <= 0.0))
1643 dec1 = 0;
1645 *decpt = dec2 ? dec2 : dec1;
1646 return 0;
1649 /***********************************************************************
1650 * _gcvt (MSVCRT.@)
1652 char * CDECL MSVCRT__gcvt( double number, int ndigit, char *buff )
1654 if(!buff) {
1655 *MSVCRT__errno() = MSVCRT_EINVAL;
1656 return NULL;
1659 if(ndigit < 0) {
1660 *MSVCRT__errno() = MSVCRT_ERANGE;
1661 return NULL;
1664 MSVCRT_sprintf(buff, "%.*g", ndigit, number);
1665 return buff;
1668 /***********************************************************************
1669 * _gcvt_s (MSVCRT.@)
1671 int CDECL MSVCRT__gcvt_s(char *buff, MSVCRT_size_t size, double number, int digits)
1673 int len;
1675 if(!buff) {
1676 *MSVCRT__errno() = MSVCRT_EINVAL;
1677 return MSVCRT_EINVAL;
1680 if( digits<0 || digits>=size) {
1681 if(size)
1682 buff[0] = '\0';
1684 *MSVCRT__errno() = MSVCRT_ERANGE;
1685 return MSVCRT_ERANGE;
1688 len = MSVCRT__scprintf("%.*g", digits, number);
1689 if(len > size) {
1690 buff[0] = '\0';
1691 *MSVCRT__errno() = MSVCRT_ERANGE;
1692 return MSVCRT_ERANGE;
1695 MSVCRT_sprintf(buff, "%.*g", digits, number);
1696 return 0;
1699 #include <stdlib.h> /* div_t, ldiv_t */
1701 /*********************************************************************
1702 * div (MSVCRT.@)
1703 * VERSION
1704 * [i386] Windows binary compatible - returns the struct in eax/edx.
1706 #ifdef __i386__
1707 unsigned __int64 CDECL MSVCRT_div(int num, int denom)
1709 div_t dt = div(num,denom);
1710 return ((unsigned __int64)dt.rem << 32) | (unsigned int)dt.quot;
1712 #else
1713 /*********************************************************************
1714 * div (MSVCRT.@)
1715 * VERSION
1716 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
1718 MSVCRT_div_t CDECL MSVCRT_div(int num, int denom)
1720 div_t dt = div(num,denom);
1721 MSVCRT_div_t ret;
1722 ret.quot = dt.quot;
1723 ret.rem = dt.rem;
1725 return ret;
1728 #endif /* ifdef __i386__ */
1731 /*********************************************************************
1732 * ldiv (MSVCRT.@)
1733 * VERSION
1734 * [i386] Windows binary compatible - returns the struct in eax/edx.
1736 #ifdef __i386__
1737 unsigned __int64 CDECL MSVCRT_ldiv(MSVCRT_long num, MSVCRT_long denom)
1739 ldiv_t ldt = ldiv(num,denom);
1740 return ((unsigned __int64)ldt.rem << 32) | (MSVCRT_ulong)ldt.quot;
1742 #else
1743 /*********************************************************************
1744 * ldiv (MSVCRT.@)
1745 * VERSION
1746 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
1748 MSVCRT_ldiv_t CDECL MSVCRT_ldiv(MSVCRT_long num, MSVCRT_long denom)
1750 ldiv_t result = ldiv(num,denom);
1752 MSVCRT_ldiv_t ret;
1753 ret.quot = result.quot;
1754 ret.rem = result.rem;
1756 return ret;
1758 #endif /* ifdef __i386__ */
1760 #ifdef __i386__
1762 /*********************************************************************
1763 * _adjust_fdiv (MSVCRT.@)
1764 * Used by the MSVC compiler to work around the Pentium FDIV bug.
1766 int MSVCRT__adjust_fdiv = 0;
1768 /***********************************************************************
1769 * _adj_fdiv_m16i (MSVCRT.@)
1771 * NOTE
1772 * I _think_ this function is intended to work around the Pentium
1773 * fdiv bug.
1775 void __stdcall _adj_fdiv_m16i( short arg )
1777 TRACE("(): stub\n");
1780 /***********************************************************************
1781 * _adj_fdiv_m32 (MSVCRT.@)
1783 * NOTE
1784 * I _think_ this function is intended to work around the Pentium
1785 * fdiv bug.
1787 void __stdcall _adj_fdiv_m32( unsigned int arg )
1789 TRACE("(): stub\n");
1792 /***********************************************************************
1793 * _adj_fdiv_m32i (MSVCRT.@)
1795 * NOTE
1796 * I _think_ this function is intended to work around the Pentium
1797 * fdiv bug.
1799 void __stdcall _adj_fdiv_m32i( int arg )
1801 TRACE("(): stub\n");
1804 /***********************************************************************
1805 * _adj_fdiv_m64 (MSVCRT.@)
1807 * NOTE
1808 * I _think_ this function is intended to work around the Pentium
1809 * fdiv bug.
1811 void __stdcall _adj_fdiv_m64( unsigned __int64 arg )
1813 TRACE("(): stub\n");
1816 /***********************************************************************
1817 * _adj_fdiv_r (MSVCRT.@)
1818 * FIXME
1819 * This function is likely to have the wrong number of arguments.
1821 * NOTE
1822 * I _think_ this function is intended to work around the Pentium
1823 * fdiv bug.
1825 void _adj_fdiv_r(void)
1827 TRACE("(): stub\n");
1830 /***********************************************************************
1831 * _adj_fdivr_m16i (MSVCRT.@)
1833 * NOTE
1834 * I _think_ this function is intended to work around the Pentium
1835 * fdiv bug.
1837 void __stdcall _adj_fdivr_m16i( short arg )
1839 TRACE("(): stub\n");
1842 /***********************************************************************
1843 * _adj_fdivr_m32 (MSVCRT.@)
1845 * NOTE
1846 * I _think_ this function is intended to work around the Pentium
1847 * fdiv bug.
1849 void __stdcall _adj_fdivr_m32( unsigned int arg )
1851 TRACE("(): stub\n");
1854 /***********************************************************************
1855 * _adj_fdivr_m32i (MSVCRT.@)
1857 * NOTE
1858 * I _think_ this function is intended to work around the Pentium
1859 * fdiv bug.
1861 void __stdcall _adj_fdivr_m32i( int arg )
1863 TRACE("(): stub\n");
1866 /***********************************************************************
1867 * _adj_fdivr_m64 (MSVCRT.@)
1869 * NOTE
1870 * I _think_ this function is intended to work around the Pentium
1871 * fdiv bug.
1873 void __stdcall _adj_fdivr_m64( unsigned __int64 arg )
1875 TRACE("(): stub\n");
1878 /***********************************************************************
1879 * _adj_fpatan (MSVCRT.@)
1880 * FIXME
1881 * This function is likely to have the wrong number of arguments.
1883 * NOTE
1884 * I _think_ this function is intended to work around the Pentium
1885 * fdiv bug.
1887 void _adj_fpatan(void)
1889 TRACE("(): stub\n");
1892 /***********************************************************************
1893 * _adj_fprem (MSVCRT.@)
1894 * FIXME
1895 * This function is likely to have the wrong number of arguments.
1897 * NOTE
1898 * I _think_ this function is intended to work around the Pentium
1899 * fdiv bug.
1901 void _adj_fprem(void)
1903 TRACE("(): stub\n");
1906 /***********************************************************************
1907 * _adj_fprem1 (MSVCRT.@)
1908 * FIXME
1909 * This function is likely to have the wrong number of arguments.
1911 * NOTE
1912 * I _think_ this function is intended to work around the Pentium
1913 * fdiv bug.
1915 void _adj_fprem1(void)
1917 TRACE("(): stub\n");
1920 /***********************************************************************
1921 * _adj_fptan (MSVCRT.@)
1922 * FIXME
1923 * This function is likely to have the wrong number of arguments.
1925 * NOTE
1926 * I _think_ this function is intended to work around the Pentium
1927 * fdiv bug.
1929 void _adj_fptan(void)
1931 TRACE("(): stub\n");
1934 /***********************************************************************
1935 * _safe_fdiv (MSVCRT.@)
1936 * FIXME
1937 * This function is likely to have the wrong number of arguments.
1939 * NOTE
1940 * I _think_ this function is intended to work around the Pentium
1941 * fdiv bug.
1943 void _safe_fdiv(void)
1945 TRACE("(): stub\n");
1948 /***********************************************************************
1949 * _safe_fdivr (MSVCRT.@)
1950 * FIXME
1951 * This function is likely to have the wrong number of arguments.
1953 * NOTE
1954 * I _think_ this function is intended to work around the Pentium
1955 * fdiv bug.
1957 void _safe_fdivr(void)
1959 TRACE("(): stub\n");
1962 /***********************************************************************
1963 * _safe_fprem (MSVCRT.@)
1964 * FIXME
1965 * This function is likely to have the wrong number of arguments.
1967 * NOTE
1968 * I _think_ this function is intended to work around the Pentium
1969 * fdiv bug.
1971 void _safe_fprem(void)
1973 TRACE("(): stub\n");
1976 /***********************************************************************
1977 * _safe_fprem1 (MSVCRT.@)
1979 * FIXME
1980 * This function is likely to have the wrong number of arguments.
1982 * NOTE
1983 * I _think_ this function is intended to work around the Pentium
1984 * fdiv bug.
1986 void _safe_fprem1(void)
1988 TRACE("(): stub\n");
1991 /***********************************************************************
1992 * __libm_sse2_acos (MSVCRT.@)
1994 void __cdecl MSVCRT___libm_sse2_acos(void)
1996 double d;
1997 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
1998 d = acos( d );
1999 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2002 /***********************************************************************
2003 * __libm_sse2_acosf (MSVCRT.@)
2005 void __cdecl MSVCRT___libm_sse2_acosf(void)
2007 float f;
2008 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2009 f = acosf( f );
2010 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2013 /***********************************************************************
2014 * __libm_sse2_asin (MSVCRT.@)
2016 void __cdecl MSVCRT___libm_sse2_asin(void)
2018 double d;
2019 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2020 d = asin( d );
2021 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2024 /***********************************************************************
2025 * __libm_sse2_asinf (MSVCRT.@)
2027 void __cdecl MSVCRT___libm_sse2_asinf(void)
2029 float f;
2030 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2031 f = asinf( f );
2032 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2035 /***********************************************************************
2036 * __libm_sse2_atan (MSVCRT.@)
2038 void __cdecl MSVCRT___libm_sse2_atan(void)
2040 double d;
2041 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2042 d = atan( d );
2043 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2046 /***********************************************************************
2047 * __libm_sse2_atan2 (MSVCRT.@)
2049 void __cdecl MSVCRT___libm_sse2_atan2(void)
2051 double d1, d2;
2052 __asm__ __volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1), "=m" (d2) );
2053 d1 = atan2( d1, d2 );
2054 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d1) );
2057 /***********************************************************************
2058 * __libm_sse2_atanf (MSVCRT.@)
2060 void __cdecl MSVCRT___libm_sse2_atanf(void)
2062 float f;
2063 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2064 f = atanf( f );
2065 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2068 /***********************************************************************
2069 * __libm_sse2_cos (MSVCRT.@)
2071 void __cdecl MSVCRT___libm_sse2_cos(void)
2073 double d;
2074 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2075 d = cos( d );
2076 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2079 /***********************************************************************
2080 * __libm_sse2_cosf (MSVCRT.@)
2082 void __cdecl MSVCRT___libm_sse2_cosf(void)
2084 float f;
2085 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2086 f = cosf( f );
2087 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2090 /***********************************************************************
2091 * __libm_sse2_exp (MSVCRT.@)
2093 void __cdecl MSVCRT___libm_sse2_exp(void)
2095 double d;
2096 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2097 d = exp( d );
2098 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2101 /***********************************************************************
2102 * __libm_sse2_expf (MSVCRT.@)
2104 void __cdecl MSVCRT___libm_sse2_expf(void)
2106 float f;
2107 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2108 f = expf( f );
2109 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2112 /***********************************************************************
2113 * __libm_sse2_log (MSVCRT.@)
2115 void __cdecl MSVCRT___libm_sse2_log(void)
2117 double d;
2118 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2119 d = log( d );
2120 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2123 /***********************************************************************
2124 * __libm_sse2_log10 (MSVCRT.@)
2126 void __cdecl MSVCRT___libm_sse2_log10(void)
2128 double d;
2129 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2130 d = log10( d );
2131 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2134 /***********************************************************************
2135 * __libm_sse2_log10f (MSVCRT.@)
2137 void __cdecl MSVCRT___libm_sse2_log10f(void)
2139 float f;
2140 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2141 f = log10f( f );
2142 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2145 /***********************************************************************
2146 * __libm_sse2_logf (MSVCRT.@)
2148 void __cdecl MSVCRT___libm_sse2_logf(void)
2150 float f;
2151 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2152 f = logf( f );
2153 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2156 /***********************************************************************
2157 * __libm_sse2_pow (MSVCRT.@)
2159 void __cdecl MSVCRT___libm_sse2_pow(void)
2161 double d1, d2;
2162 __asm__ __volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1), "=m" (d2) );
2163 d1 = pow( d1, d2 );
2164 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d1) );
2167 /***********************************************************************
2168 * __libm_sse2_powf (MSVCRT.@)
2170 void __cdecl MSVCRT___libm_sse2_powf(void)
2172 float f1, f2;
2173 __asm__ __volatile__( "movd %%xmm0,%0; movd %%xmm1,%1" : "=g" (f1), "=g" (f2) );
2174 f1 = powf( f1, f2 );
2175 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f1) );
2178 /***********************************************************************
2179 * __libm_sse2_sin (MSVCRT.@)
2181 void __cdecl MSVCRT___libm_sse2_sin(void)
2183 double d;
2184 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2185 d = sin( d );
2186 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2189 /***********************************************************************
2190 * __libm_sse2_sinf (MSVCRT.@)
2192 void __cdecl MSVCRT___libm_sse2_sinf(void)
2194 float f;
2195 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2196 f = sinf( f );
2197 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2200 /***********************************************************************
2201 * __libm_sse2_tan (MSVCRT.@)
2203 void __cdecl MSVCRT___libm_sse2_tan(void)
2205 double d;
2206 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2207 d = tan( d );
2208 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2211 /***********************************************************************
2212 * __libm_sse2_tanf (MSVCRT.@)
2214 void __cdecl MSVCRT___libm_sse2_tanf(void)
2216 float f;
2217 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2218 f = tanf( f );
2219 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2222 /***********************************************************************
2223 * __libm_sse2_sqrt_precise (MSVCR110.@)
2225 void __cdecl MSVCRT___libm_sse2_sqrt_precise(void)
2227 double d;
2228 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2229 d = sqrt( d );
2230 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2233 #endif /* __i386__ */
2235 /*********************************************************************
2236 * cbrt (MSVCR120.@)
2238 double CDECL MSVCR120_cbrt(double x)
2240 #ifdef HAVE_CBRT
2241 return cbrt(x);
2242 #else
2243 return x < 0 ? -pow(-x, 1.0 / 3.0) : pow(x, 1.0 / 3.0);
2244 #endif
2247 /*********************************************************************
2248 * cbrtf (MSVCR120.@)
2250 float CDECL MSVCR120_cbrtf(float x)
2252 #ifdef HAVE_CBRTF
2253 return cbrtf(x);
2254 #else
2255 return MSVCR120_cbrt(x);
2256 #endif
2259 /*********************************************************************
2260 * cbrtl (MSVCR120.@)
2262 LDOUBLE CDECL MSVCR120_cbrtl(LDOUBLE x)
2264 return MSVCR120_cbrt(x);
2267 /*********************************************************************
2268 * exp2 (MSVCR120.@)
2270 double CDECL MSVCR120_exp2(double x)
2272 #ifdef HAVE_EXP2
2273 return exp2(x);
2274 #else
2275 return pow(2, x);
2276 #endif
2279 /*********************************************************************
2280 * exp2f (MSVCR120.@)
2282 float CDECL MSVCR120_exp2f(float x)
2284 #ifdef HAVE_EXP2F
2285 return exp2f(x);
2286 #else
2287 return MSVCR120_exp2(x);
2288 #endif
2291 /*********************************************************************
2292 * exp2l (MSVCR120.@)
2294 LDOUBLE CDECL MSVCR120_exp2l(LDOUBLE x)
2296 return MSVCR120_exp2(x);
2299 /*********************************************************************
2300 * log2 (MSVCR120.@)
2302 double CDECL MSVCR120_log2(double x)
2304 #ifdef HAVE_LOG2
2305 return log2(x);
2306 #else
2307 return log(x) / log(2);
2308 #endif
2311 /*********************************************************************
2312 * log2f (MSVCR120.@)
2314 float CDECL MSVCR120_log2f(float x)
2316 #ifdef HAVE_LOG2F
2317 return log2f(x);
2318 #else
2319 return MSVCR120_log2(x);
2320 #endif
2323 /*********************************************************************
2324 * log2l (MSVCR120.@)
2326 LDOUBLE CDECL MSVCR120_log2l(LDOUBLE x)
2328 return MSVCR120_log2(x);
2331 /*********************************************************************
2332 * rint (MSVCR120.@)
2334 double CDECL MSVCR120_rint(double x)
2336 #ifdef HAVE_RINT
2337 return rint(x);
2338 #else
2339 return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
2340 #endif
2343 /*********************************************************************
2344 * rintf (MSVCR120.@)
2346 float CDECL MSVCR120_rintf(float x)
2348 #ifdef HAVE_RINTF
2349 return rintf(x);
2350 #else
2351 return MSVCR120_rint(x);
2352 #endif
2355 /*********************************************************************
2356 * rintl (MSVCR120.@)
2358 LDOUBLE CDECL MSVCR120_rintl(LDOUBLE x)
2360 return MSVCR120_rint(x);
2363 /*********************************************************************
2364 * lrint (MSVCR120.@)
2366 MSVCRT_long CDECL MSVCR120_lrint(double x)
2368 #ifdef HAVE_LRINT
2369 return lrint(x);
2370 #else
2371 return MSVCR120_rint(x);
2372 #endif
2375 /*********************************************************************
2376 * lrintf (MSVCR120.@)
2378 MSVCRT_long CDECL MSVCR120_lrintf(float x)
2380 #ifdef HAVE_LRINTF
2381 return lrintf(x);
2382 #else
2383 return MSVCR120_lrint(x);
2384 #endif
2387 /*********************************************************************
2388 * lrintl (MSVCR120.@)
2390 MSVCRT_long CDECL MSVCR120_lrintl(LDOUBLE x)
2392 return MSVCR120_lrint(x);
2395 /*********************************************************************
2396 * llrint (MSVCR120.@)
2398 MSVCRT_longlong CDECL MSVCR120_llrint(double x)
2400 #ifdef HAVE_LLRINT
2401 return llrint(x);
2402 #else
2403 return MSVCR120_rint(x);
2404 #endif
2407 /*********************************************************************
2408 * llrintf (MSVCR120.@)
2410 MSVCRT_longlong CDECL MSVCR120_llrintf(float x)
2412 #ifdef HAVE_LLRINTF
2413 return llrintf(x);
2414 #else
2415 return MSVCR120_llrint(x);
2416 #endif
2419 /*********************************************************************
2420 * rintl (MSVCR120.@)
2422 MSVCRT_longlong CDECL MSVCR120_llrintl(LDOUBLE x)
2424 return MSVCR120_llrint(x);
2427 /*********************************************************************
2428 * round (MSVCR120.@)
2430 double CDECL MSVCR120_round(double x)
2432 #ifdef HAVE_ROUND
2433 return round(x);
2434 #else
2435 return MSVCR120_rint(x);
2436 #endif
2439 /*********************************************************************
2440 * roundf (MSVCR120.@)
2442 float CDECL MSVCR120_roundf(float x)
2444 #ifdef HAVE_ROUNDF
2445 return roundf(x);
2446 #else
2447 return MSVCR120_round(x);
2448 #endif
2451 /*********************************************************************
2452 * roundl (MSVCR120.@)
2454 LDOUBLE CDECL MSVCR120_roundl(LDOUBLE x)
2456 return MSVCR120_round(x);
2459 /*********************************************************************
2460 * lround (MSVCR120.@)
2462 MSVCRT_long CDECL MSVCR120_lround(double x)
2464 #ifdef HAVE_LROUND
2465 return lround(x);
2466 #else
2467 return MSVCR120_round(x);
2468 #endif
2471 /*********************************************************************
2472 * lroundf (MSVCR120.@)
2474 MSVCRT_long CDECL MSVCR120_lroundf(float x)
2476 #ifdef HAVE_LROUNDF
2477 return lroundf(x);
2478 #else
2479 return MSVCR120_lround(x);
2480 #endif
2483 /*********************************************************************
2484 * lroundl (MSVCR120.@)
2486 MSVCRT_long CDECL MSVCR120_lroundl(LDOUBLE x)
2488 return MSVCR120_lround(x);
2491 /*********************************************************************
2492 * llround (MSVCR120.@)
2494 MSVCRT_longlong CDECL MSVCR120_llround(double x)
2496 #ifdef HAVE_LLROUND
2497 return llround(x);
2498 #else
2499 return MSVCR120_round(x);
2500 #endif
2503 /*********************************************************************
2504 * llroundf (MSVCR120.@)
2506 MSVCRT_longlong CDECL MSVCR120_llroundf(float x)
2508 #ifdef HAVE_LLROUNDF
2509 return llroundf(x);
2510 #else
2511 return MSVCR120_llround(x);
2512 #endif
2515 /*********************************************************************
2516 * roundl (MSVCR120.@)
2518 MSVCRT_longlong CDECL MSVCR120_llroundl(LDOUBLE x)
2520 return MSVCR120_llround(x);
2523 /*********************************************************************
2524 * trunc (MSVCR120.@)
2526 double CDECL MSVCR120_trunc(double x)
2528 #ifdef HAVE_TRUNC
2529 return trunc(x);
2530 #else
2531 return (x > 0) ? floor(x) : ceil(x);
2532 #endif
2535 /*********************************************************************
2536 * truncf (MSVCR120.@)
2538 float CDECL MSVCR120_truncf(float x)
2540 #ifdef HAVE_TRUNCF
2541 return truncf(x);
2542 #else
2543 return MSVCR120_trunc(x);
2544 #endif
2547 /*********************************************************************
2548 * truncl (MSVCR120.@)
2550 LDOUBLE CDECL MSVCR120_truncl(LDOUBLE x)
2552 return MSVCR120_trunc(x);
2555 /*********************************************************************
2556 * _dclass (MSVCR120.@)
2558 short CDECL MSVCR120__dclass(double x)
2560 switch (MSVCRT__fpclass(x)) {
2561 case MSVCRT__FPCLASS_QNAN:
2562 case MSVCRT__FPCLASS_SNAN:
2563 return MSVCRT_FP_NAN;
2564 case MSVCRT__FPCLASS_NINF:
2565 case MSVCRT__FPCLASS_PINF:
2566 return MSVCRT_FP_INFINITE;
2567 case MSVCRT__FPCLASS_ND:
2568 case MSVCRT__FPCLASS_PD:
2569 return MSVCRT_FP_SUBNORMAL;
2570 case MSVCRT__FPCLASS_NN:
2571 case MSVCRT__FPCLASS_PN:
2572 default:
2573 return MSVCRT_FP_NORMAL;
2574 case MSVCRT__FPCLASS_NZ:
2575 case MSVCRT__FPCLASS_PZ:
2576 return MSVCRT_FP_ZERO;
2580 /*********************************************************************
2581 * _fdclass (MSVCR120.@)
2583 short CDECL MSVCR120__fdclass(float x)
2585 return MSVCR120__dclass(x);
2588 /*********************************************************************
2589 * _ldclass (MSVCR120.@)
2591 short CDECL MSVCR120__ldclass(LDOUBLE x)
2593 return MSVCR120__dclass(x);
2596 /*********************************************************************
2597 * _dtest (MSVCR120.@)
2599 short CDECL MSVCR120__dtest(double *x)
2601 return MSVCR120__dclass(*x);
2604 /*********************************************************************
2605 * _fdtest (MSVCR120.@)
2607 short CDECL MSVCR120__fdtest(float *x)
2609 return MSVCR120__dclass(*x);
2612 /*********************************************************************
2613 * _ldtest (MSVCR120.@)
2615 short CDECL MSVCR120__ldtest(LDOUBLE *x)
2617 return MSVCR120__dclass(*x);
2620 /*********************************************************************
2621 * erff (MSVCR120.@)
2623 float CDECL MSVCR120_erff(float x)
2625 #ifdef HAVE_ERFF
2626 return erff(x);
2627 #else
2628 FIXME( "not implemented\n" );
2629 return 0.0f;
2630 #endif
2633 /*********************************************************************
2634 * erf (MSVCR120.@)
2636 double CDECL MSVCR120_erf(double x)
2638 #ifdef HAVE_ERF
2639 return erf(x);
2640 #else
2641 FIXME( "not implemented\n" );
2642 return 0.0;
2643 #endif
2646 /*********************************************************************
2647 * erfl (MSVCR120.@)
2649 LDOUBLE CDECL MSVCR120_erfl(LDOUBLE x)
2651 return MSVCR120_erf(x);
2654 /*********************************************************************
2655 * fmaxf (MSVCR120.@)
2657 float CDECL MSVCR120_fmaxf(float x, float y)
2659 if(isnanf(x))
2660 return y;
2661 if(isnanf(y))
2662 return x;
2663 if(x==0 && y==0)
2664 return signbit(x) ? y : x;
2665 return x<y ? y : x;
2668 /*********************************************************************
2669 * fmax (MSVCR120.@)
2671 double CDECL MSVCR120_fmax(double x, double y)
2673 if(isnan(x))
2674 return y;
2675 if(isnan(y))
2676 return x;
2677 if(x==0 && y==0)
2678 return signbit(x) ? y : x;
2679 return x<y ? y : x;
2682 /*********************************************************************
2683 * _fdsign (MSVCR120.@)
2685 int CDECL MSVCR120__fdsign(float x)
2687 return signbit(x) ? 0x8000 : 0;
2690 /*********************************************************************
2691 * _dsign (MSVCR120.@)
2693 int CDECL MSVCR120__dsign(double x)
2695 return signbit(x) ? 0x8000 : 0;
2699 /*********************************************************************
2700 * _dpcomp (MSVCR120.@)
2702 int CDECL MSVCR120__dpcomp(double x, double y)
2704 if(isnan(x) || isnan(y))
2705 return 0;
2707 if(x == y) return 2;
2708 return x < y ? 1 : 4;
2711 /*********************************************************************
2712 * _fdpcomp (MSVCR120.@)
2714 int CDECL MSVCR120__fdpcomp(float x, float y)
2716 return MSVCR120__dpcomp(x, y);
2719 /*********************************************************************
2720 * fminf (MSVCR120.@)
2722 float CDECL MSVCR120_fminf(float x, float y)
2724 if(isnanf(x))
2725 return y;
2726 if(isnanf(y))
2727 return x;
2728 if(x==0 && y==0)
2729 return signbit(x) ? x : y;
2730 return x<y ? x : y;
2733 /*********************************************************************
2734 * fmin (MSVCR120.@)
2736 double CDECL MSVCR120_fmin(double x, double y)
2738 if(isnan(x))
2739 return y;
2740 if(isnan(y))
2741 return x;
2742 if(x==0 && y==0)
2743 return signbit(x) ? x : y;
2744 return x<y ? x : y;
2747 /*********************************************************************
2748 * asinh (MSVCR120.@)
2750 double CDECL MSVCR120_asinh(double x)
2752 #ifdef HAVE_ASINH
2753 return asinh(x);
2754 #else
2755 FIXME( "not implemented\n" );
2756 return 0.0;
2757 #endif
2760 /*********************************************************************
2761 * asinhf (MSVCR120.@)
2763 float CDECL MSVCR120_asinhf(float x)
2765 #ifdef HAVE_ASINHF
2766 return asinhf(x);
2767 #else
2768 FIXME( "not implemented\n" );
2769 return 0.0f;
2770 #endif
2773 /*********************************************************************
2774 * asinhl (MSVCR120.@)
2776 LDOUBLE CDECL MSVCR120_asinhl(LDOUBLE x)
2778 return MSVCR120_asinh(x);