Changes in crossover-wine-src-6.1.0 except for configure
[wine/hacks.git] / dlls / msvcrt / math.c
blob6f8da46b66cfdaa5166aad140c0547c96733628a
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"
22 #include <stdio.h>
23 #define __USE_ISOC9X 1
24 #define __USE_ISOC99 1
25 #include <math.h>
26 #ifdef HAVE_IEEEFP_H
27 #include <ieeefp.h>
28 #endif
30 #include "msvcrt.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
36 #ifndef HAVE_FINITE
37 #ifndef finite /* Could be a macro */
38 #ifdef isfinite
39 #define finite(x) isfinite(x)
40 #else
41 #define finite(x) (!isnan(x)) /* At least catch some cases */
42 #endif
43 #endif
44 #endif
46 #ifndef signbit
47 #define signbit(x) 0
48 #endif
50 typedef int (*MSVCRT_matherr_func)(struct MSVCRT__exception *);
52 static MSVCRT_matherr_func MSVCRT_default_matherr_func = NULL;
54 /*********************************************************************
55 * MSVCRT_acos (MSVCRT.@)
57 double CDECL MSVCRT_acos( double x )
59 if (x < -1.0 || x > 1.0 || !finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
60 return acos(x);
63 /*********************************************************************
64 * MSVCRT_asin (MSVCRT.@)
66 double CDECL MSVCRT_asin( double x )
68 if (x < -1.0 || x > 1.0 || !finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
69 return asin(x);
72 /*********************************************************************
73 * MSVCRT_atan (MSVCRT.@)
75 double CDECL MSVCRT_atan( double x )
77 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
78 return atan(x);
81 /*********************************************************************
82 * MSVCRT_atan2 (MSVCRT.@)
84 double CDECL MSVCRT_atan2( double x, double y )
86 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
87 return atan2(x,y);
90 /*********************************************************************
91 * MSVCRT_cos (MSVCRT.@)
93 double CDECL MSVCRT_cos( double x )
95 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
96 return cos(x);
99 /*********************************************************************
100 * MSVCRT_cosh (MSVCRT.@)
102 double CDECL MSVCRT_cosh( double x )
104 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
105 return cosh(x);
108 /*********************************************************************
109 * MSVCRT_exp (MSVCRT.@)
111 double CDECL MSVCRT_exp( double x )
113 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
114 return exp(x);
117 /*********************************************************************
118 * MSVCRT_fmod (MSVCRT.@)
120 double CDECL MSVCRT_fmod( double x, double y )
122 if (!finite(x) || !finite(y)) *MSVCRT__errno() = MSVCRT_EDOM;
123 return fmod(x,y);
126 /*********************************************************************
127 * MSVCRT_log (MSVCRT.@)
129 double CDECL MSVCRT_log( double x)
131 if (x < 0.0 || !finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
132 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
133 return log(x);
136 /*********************************************************************
137 * MSVCRT_log10 (MSVCRT.@)
139 double CDECL MSVCRT_log10( double x )
141 if (x < 0.0 || !finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
142 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
143 return log10(x);
146 /*********************************************************************
147 * MSVCRT_pow (MSVCRT.@)
149 double CDECL MSVCRT_pow( double x, double y )
151 /* FIXME: If x < 0 and y is not integral, set EDOM */
152 double z = pow(x,y);
153 if (!finite(z)) *MSVCRT__errno() = MSVCRT_EDOM;
154 return z;
157 /*********************************************************************
158 * MSVCRT_sin (MSVCRT.@)
160 double CDECL MSVCRT_sin( double x )
162 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
163 return sin(x);
166 /*********************************************************************
167 * MSVCRT_sinh (MSVCRT.@)
169 double CDECL MSVCRT_sinh( double x )
171 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
172 return sinh(x);
175 /*********************************************************************
176 * MSVCRT_sqrt (MSVCRT.@)
178 double CDECL MSVCRT_sqrt( double x )
180 if (x < 0.0 || !finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
181 return sqrt(x);
184 /*********************************************************************
185 * MSVCRT_tan (MSVCRT.@)
187 double CDECL MSVCRT_tan( double x )
189 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
190 return tan(x);
193 /*********************************************************************
194 * MSVCRT_tanh (MSVCRT.@)
196 double CDECL MSVCRT_tanh( double x )
198 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
199 return tanh(x);
203 #if defined(__GNUC__) && defined(__i386__)
205 #define FPU_DOUBLE(var) double var; \
206 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
207 #define FPU_DOUBLES(var1,var2) double var1,var2; \
208 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
209 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
211 /*********************************************************************
212 * _CIacos (MSVCRT.@)
214 double CDECL _CIacos(void)
216 FPU_DOUBLE(x);
217 return MSVCRT_acos(x);
220 /*********************************************************************
221 * _CIasin (MSVCRT.@)
223 double CDECL _CIasin(void)
225 FPU_DOUBLE(x);
226 return MSVCRT_asin(x);
229 /*********************************************************************
230 * _CIatan (MSVCRT.@)
232 double CDECL _CIatan(void)
234 FPU_DOUBLE(x);
235 return MSVCRT_atan(x);
238 /*********************************************************************
239 * _CIatan2 (MSVCRT.@)
241 double CDECL _CIatan2(void)
243 FPU_DOUBLES(x,y);
244 return MSVCRT_atan2(x,y);
247 /*********************************************************************
248 * _CIcos (MSVCRT.@)
250 double CDECL _CIcos(void)
252 FPU_DOUBLE(x);
253 return MSVCRT_cos(x);
256 /*********************************************************************
257 * _CIcosh (MSVCRT.@)
259 double CDECL _CIcosh(void)
261 FPU_DOUBLE(x);
262 return MSVCRT_cosh(x);
265 /*********************************************************************
266 * _CIexp (MSVCRT.@)
268 double CDECL _CIexp(void)
270 FPU_DOUBLE(x);
271 return MSVCRT_exp(x);
274 /*********************************************************************
275 * _CIfmod (MSVCRT.@)
277 double CDECL _CIfmod(void)
279 FPU_DOUBLES(x,y);
280 return MSVCRT_fmod(x,y);
283 /*********************************************************************
284 * _CIlog (MSVCRT.@)
286 double CDECL _CIlog(void)
288 FPU_DOUBLE(x);
289 return MSVCRT_log(x);
292 /*********************************************************************
293 * _CIlog10 (MSVCRT.@)
295 double CDECL _CIlog10(void)
297 FPU_DOUBLE(x);
298 return MSVCRT_log10(x);
301 /*********************************************************************
302 * _CIpow (MSVCRT.@)
304 double CDECL _CIpow(void)
306 FPU_DOUBLES(x,y);
307 return MSVCRT_pow(x,y);
310 /*********************************************************************
311 * _CIsin (MSVCRT.@)
313 double CDECL _CIsin(void)
315 FPU_DOUBLE(x);
316 return MSVCRT_sin(x);
319 /*********************************************************************
320 * _CIsinh (MSVCRT.@)
322 double CDECL _CIsinh(void)
324 FPU_DOUBLE(x);
325 return MSVCRT_sinh(x);
328 /*********************************************************************
329 * _CIsqrt (MSVCRT.@)
331 double CDECL _CIsqrt(void)
333 FPU_DOUBLE(x);
334 return MSVCRT_sqrt(x);
337 /*********************************************************************
338 * _CItan (MSVCRT.@)
340 double CDECL _CItan(void)
342 FPU_DOUBLE(x);
343 return MSVCRT_tan(x);
346 /*********************************************************************
347 * _CItanh (MSVCRT.@)
349 double CDECL _CItanh(void)
351 FPU_DOUBLE(x);
352 return MSVCRT_tanh(x);
355 #else /* defined(__GNUC__) && defined(__i386__) */
357 /* The above cannot be called on non x86 platforms, stub them for linking */
359 #define IX86_ONLY(func) double func(void) { return 0.0; }
361 IX86_ONLY(_CIacos)
362 IX86_ONLY(_CIasin)
363 IX86_ONLY(_CIatan)
364 IX86_ONLY(_CIatan2)
365 IX86_ONLY(_CIcos)
366 IX86_ONLY(_CIcosh)
367 IX86_ONLY(_CIexp)
368 IX86_ONLY(_CIfmod)
369 IX86_ONLY(_CIlog)
370 IX86_ONLY(_CIlog10)
371 IX86_ONLY(_CIpow)
372 IX86_ONLY(_CIsin)
373 IX86_ONLY(_CIsinh)
374 IX86_ONLY(_CIsqrt)
375 IX86_ONLY(_CItan)
376 IX86_ONLY(_CItanh)
378 #endif /* defined(__GNUC__) && defined(__i386__) */
380 /*********************************************************************
381 * _fpclass (MSVCRT.@)
383 int CDECL _fpclass(double num)
385 #if defined(HAVE_FPCLASS) || defined(fpclass)
386 switch (fpclass( num ))
388 #ifdef FP_SNAN
389 case FP_SNAN: return MSVCRT__FPCLASS_SNAN;
390 #endif
391 #ifdef FP_QNAN
392 case FP_QNAN: return MSVCRT__FPCLASS_QNAN;
393 #endif
394 #ifdef FP_NINF
395 case FP_NINF: return MSVCRT__FPCLASS_NINF;
396 #endif
397 #ifdef FP_PINF
398 case FP_PINF: return MSVCRT__FPCLASS_PINF;
399 #endif
400 #ifdef FP_NDENORM
401 case FP_NDENORM: return MSVCRT__FPCLASS_ND;
402 #endif
403 #ifdef FP_PDENORM
404 case FP_PDENORM: return MSVCRT__FPCLASS_PD;
405 #endif
406 #ifdef FP_NZERO
407 case FP_NZERO: return MSVCRT__FPCLASS_NZ;
408 #endif
409 #ifdef FP_PZERO
410 case FP_PZERO: return MSVCRT__FPCLASS_PZ;
411 #endif
412 #ifdef FP_NNORM
413 case FP_NNORM: return MSVCRT__FPCLASS_NN;
414 #endif
415 #ifdef FP_PNORM
416 case FP_PNORM: return MSVCRT__FPCLASS_PN;
417 #endif
419 return MSVCRT__FPCLASS_PN;
420 #elif defined (fpclassify)
421 switch (fpclassify( num ))
423 case FP_NAN: return MSVCRT__FPCLASS_QNAN;
424 case FP_INFINITE: return signbit(num) ? MSVCRT__FPCLASS_NINF : MSVCRT__FPCLASS_PINF;
425 case FP_SUBNORMAL: return signbit(num) ?MSVCRT__FPCLASS_ND : MSVCRT__FPCLASS_PD;
426 case FP_ZERO: return signbit(num) ? MSVCRT__FPCLASS_NZ : MSVCRT__FPCLASS_PZ;
428 return signbit(num) ? MSVCRT__FPCLASS_NN : MSVCRT__FPCLASS_PN;
429 #else
430 if (!finite(num))
431 return MSVCRT__FPCLASS_QNAN;
432 return num == 0.0 ? MSVCRT__FPCLASS_PZ : (num < 0 ? MSVCRT__FPCLASS_NN : MSVCRT__FPCLASS_PN);
433 #endif
436 /*********************************************************************
437 * _rotl (MSVCRT.@)
439 unsigned int CDECL _rotl(unsigned int num, int shift)
441 shift &= 31;
442 return (num << shift) | (num >> (32-shift));
445 /*********************************************************************
446 * _logb (MSVCRT.@)
448 double CDECL _logb(double num)
450 if (!finite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
451 return logb(num);
454 /*********************************************************************
455 * _lrotl (MSVCRT.@)
457 unsigned long CDECL _lrotl(unsigned long num, int shift)
459 shift &= 0x1f;
460 return (num << shift) | (num >> (32-shift));
463 /*********************************************************************
464 * _lrotr (MSVCRT.@)
466 unsigned long CDECL _lrotr(unsigned long num, int shift)
468 shift &= 0x1f;
469 return (num >> shift) | (num << (32-shift));
472 /*********************************************************************
473 * _rotr (MSVCRT.@)
475 unsigned int CDECL _rotr(unsigned int num, int shift)
477 shift &= 0x1f;
478 return (num >> shift) | (num << (32-shift));
481 /*********************************************************************
482 * _scalb (MSVCRT.@)
484 double CDECL _scalb(double num, long power)
486 /* Note - Can't forward directly as libc expects y as double */
487 double dblpower = (double)power;
488 if (!finite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
489 return scalb(num, dblpower);
492 /*********************************************************************
493 * _hypot (MSVCRT.@)
495 double CDECL _hypot(double x, double y)
497 /* FIXME: errno handling */
498 return hypot( x, y );
501 /*********************************************************************
502 * ceil (MSVCRT.@)
504 double CDECL MSVCRT_ceil( double x )
506 return ceil(x);
509 /*********************************************************************
510 * floor (MSVCRT.@)
512 double CDECL MSVCRT_floor( double x )
514 return floor(x);
517 /*********************************************************************
518 * fabs (MSVCRT.@)
520 double CDECL MSVCRT_fabs( double x )
522 return fabs(x);
525 /*********************************************************************
526 * frexp (MSVCRT.@)
528 double CDECL MSVCRT_frexp( double x, int *exp )
530 return frexp( x, exp );
533 /*********************************************************************
534 * modf (MSVCRT.@)
536 double CDECL MSVCRT_modf( double x, double *iptr )
538 return modf( x, iptr );
541 /*********************************************************************
542 * _matherr (MSVCRT.@)
544 int CDECL MSVCRT__matherr(struct MSVCRT__exception *e)
546 if (e)
547 TRACE("(%p = %d, %s, %g %g %g)\n",e, e->type, e->name, e->arg1, e->arg2,
548 e->retval);
549 else
550 TRACE("(null)\n");
551 if (MSVCRT_default_matherr_func)
552 return MSVCRT_default_matherr_func(e);
553 ERR(":Unhandled math error!\n");
554 return 0;
557 /*********************************************************************
558 * __setusermatherr (MSVCRT.@)
560 void CDECL MSVCRT___setusermatherr(MSVCRT_matherr_func func)
562 MSVCRT_default_matherr_func = func;
563 TRACE(":new matherr handler %p\n", func);
566 /**********************************************************************
567 * _statusfp (MSVCRT.@)
569 unsigned int CDECL _statusfp(void)
571 unsigned int retVal = 0;
572 #if defined(__GNUC__) && defined(__i386__)
573 unsigned int fpword;
575 __asm__ __volatile__( "fstsw %0" : "=m" (fpword) : );
576 if (fpword & 0x1) retVal |= MSVCRT__SW_INVALID;
577 if (fpword & 0x2) retVal |= MSVCRT__SW_DENORMAL;
578 if (fpword & 0x4) retVal |= MSVCRT__SW_ZERODIVIDE;
579 if (fpword & 0x8) retVal |= MSVCRT__SW_OVERFLOW;
580 if (fpword & 0x10) retVal |= MSVCRT__SW_UNDERFLOW;
581 if (fpword & 0x20) retVal |= MSVCRT__SW_INEXACT;
582 #else
583 FIXME(":Not implemented!\n");
584 #endif
585 return retVal;
588 /*********************************************************************
589 * _clearfp (MSVCRT.@)
591 unsigned int CDECL _clearfp(void)
593 unsigned int retVal = _statusfp();
594 #if defined(__GNUC__) && defined(__i386__)
595 __asm__ __volatile__( "fnclex" );
596 #else
597 FIXME(":Not Implemented\n");
598 #endif
599 return retVal;
602 /*********************************************************************
603 * __fpecode (MSVCRT.@)
605 int * CDECL __fpecode(void)
607 return &msvcrt_get_thread_data()->fpecode;
610 /*********************************************************************
611 * ldexp (MSVCRT.@)
613 double CDECL MSVCRT_ldexp(double num, long exp)
615 double z = ldexp(num,exp);
617 if (!finite(z))
618 *MSVCRT__errno() = MSVCRT_ERANGE;
619 else if (z == 0 && signbit(z))
620 z = 0.0; /* Convert -0 -> +0 */
621 return z;
624 /*********************************************************************
625 * _cabs (MSVCRT.@)
627 double CDECL MSVCRT__cabs(struct MSVCRT__complex num)
629 return sqrt(num.x * num.x + num.y * num.y);
632 /*********************************************************************
633 * _chgsign (MSVCRT.@)
635 double CDECL _chgsign(double num)
637 /* FIXME: +-infinity,Nan not tested */
638 return -num;
641 /*********************************************************************
642 * _control87 (MSVCRT.@)
644 unsigned int CDECL _control87(unsigned int newval, unsigned int mask)
646 #if defined(__GNUC__) && defined(__i386__)
647 unsigned int fpword = 0;
648 unsigned int flags = 0;
650 TRACE("(%08x, %08x): Called\n", newval, mask);
652 /* Get fp control word */
653 __asm__ __volatile__( "fstcw %0" : "=m" (fpword) : );
655 TRACE("Control word before : %08x\n", fpword);
657 /* Convert into mask constants */
658 if (fpword & 0x1) flags |= MSVCRT__EM_INVALID;
659 if (fpword & 0x2) flags |= MSVCRT__EM_DENORMAL;
660 if (fpword & 0x4) flags |= MSVCRT__EM_ZERODIVIDE;
661 if (fpword & 0x8) flags |= MSVCRT__EM_OVERFLOW;
662 if (fpword & 0x10) flags |= MSVCRT__EM_UNDERFLOW;
663 if (fpword & 0x20) flags |= MSVCRT__EM_INEXACT;
664 switch(fpword & 0xC00) {
665 case 0xC00: flags |= MSVCRT__RC_UP|MSVCRT__RC_DOWN; break;
666 case 0x800: flags |= MSVCRT__RC_UP; break;
667 case 0x400: flags |= MSVCRT__RC_DOWN; break;
669 switch(fpword & 0x300) {
670 case 0x0: flags |= MSVCRT__PC_24; break;
671 case 0x200: flags |= MSVCRT__PC_53; break;
672 case 0x300: flags |= MSVCRT__PC_64; break;
674 if (fpword & 0x1000) flags |= MSVCRT__IC_AFFINE;
676 /* Mask with parameters */
677 flags = (flags & ~mask) | (newval & mask);
679 /* Convert (masked) value back to fp word */
680 fpword = 0;
681 if (flags & MSVCRT__EM_INVALID) fpword |= 0x1;
682 if (flags & MSVCRT__EM_DENORMAL) fpword |= 0x2;
683 if (flags & MSVCRT__EM_ZERODIVIDE) fpword |= 0x4;
684 if (flags & MSVCRT__EM_OVERFLOW) fpword |= 0x8;
685 if (flags & MSVCRT__EM_UNDERFLOW) fpword |= 0x10;
686 if (flags & MSVCRT__EM_INEXACT) fpword |= 0x20;
687 switch(flags & (MSVCRT__RC_UP | MSVCRT__RC_DOWN)) {
688 case MSVCRT__RC_UP|MSVCRT__RC_DOWN: fpword |= 0xC00; break;
689 case MSVCRT__RC_UP: fpword |= 0x800; break;
690 case MSVCRT__RC_DOWN: fpword |= 0x400; break;
692 switch (flags & (MSVCRT__PC_24 | MSVCRT__PC_53)) {
693 case MSVCRT__PC_64: fpword |= 0x300; break;
694 case MSVCRT__PC_53: fpword |= 0x200; break;
695 case MSVCRT__PC_24: fpword |= 0x0; break;
697 if (flags & MSVCRT__IC_AFFINE) fpword |= 0x1000;
699 TRACE("Control word after : %08x\n", fpword);
701 /* Put fp control word */
702 __asm__ __volatile__( "fldcw %0" : : "m" (fpword) );
704 return flags;
705 #else
706 FIXME(":Not Implemented!\n");
707 return 0;
708 #endif
711 /*********************************************************************
712 * _controlfp (MSVCRT.@)
714 unsigned int CDECL _controlfp(unsigned int newval, unsigned int mask)
716 #ifdef __i386__
717 return _control87( newval, mask & ~MSVCRT__EM_DENORMAL );
718 #else
719 FIXME(":Not Implemented!\n");
720 return 0;
721 #endif
724 /*********************************************************************
725 * _copysign (MSVCRT.@)
727 double CDECL _copysign(double num, double sign)
729 /* FIXME: Behaviour for Nan/Inf? */
730 if (sign < 0.0)
731 return num < 0.0 ? num : -num;
732 return num < 0.0 ? -num : num;
735 /*********************************************************************
736 * _finite (MSVCRT.@)
738 int CDECL _finite(double num)
740 return (finite(num)?1:0); /* See comment for _isnan() */
743 /*********************************************************************
744 * _fpreset (MSVCRT.@)
746 void CDECL _fpreset(void)
748 #if defined(__GNUC__) && defined(__i386__)
749 __asm__ __volatile__( "fninit" );
750 #else
751 FIXME(":Not Implemented!\n");
752 #endif
755 /*********************************************************************
756 * _isnan (MSVCRT.@)
758 INT CDECL _isnan(double num)
760 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
761 * Do the same, as the result may be used in calculations
763 return isnan(num) ? 1 : 0;
766 /*********************************************************************
767 * _j0 (MSVCRT.@)
769 double CDECL _j0(double num)
771 /* FIXME: errno handling */
772 return j0(num);
775 /*********************************************************************
776 * _j1 (MSVCRT.@)
778 double CDECL _j1(double num)
780 /* FIXME: errno handling */
781 return j1(num);
784 /*********************************************************************
785 * jn (MSVCRT.@)
787 double CDECL _jn(int n, double num)
789 /* FIXME: errno handling */
790 return jn(n, num);
793 /*********************************************************************
794 * _y0 (MSVCRT.@)
796 double CDECL _y0(double num)
798 double retval;
799 if (!finite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
800 retval = y0(num);
801 if (_fpclass(retval) == MSVCRT__FPCLASS_NINF)
803 *MSVCRT__errno() = MSVCRT_EDOM;
804 retval = sqrt(-1);
806 return retval;
809 /*********************************************************************
810 * _y1 (MSVCRT.@)
812 double CDECL _y1(double num)
814 double retval;
815 if (!finite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
816 retval = y1(num);
817 if (_fpclass(retval) == MSVCRT__FPCLASS_NINF)
819 *MSVCRT__errno() = MSVCRT_EDOM;
820 retval = sqrt(-1);
822 return retval;
825 /*********************************************************************
826 * _yn (MSVCRT.@)
828 double CDECL _yn(int order, double num)
830 double retval;
831 if (!finite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
832 retval = yn(order,num);
833 if (_fpclass(retval) == MSVCRT__FPCLASS_NINF)
835 *MSVCRT__errno() = MSVCRT_EDOM;
836 retval = sqrt(-1);
838 return retval;
841 /*********************************************************************
842 * _nextafter (MSVCRT.@)
844 double CDECL _nextafter(double num, double next)
846 double retval;
847 if (!finite(num) || !finite(next)) *MSVCRT__errno() = MSVCRT_EDOM;
848 retval = nextafter(num,next);
849 return retval;
852 /*********************************************************************
853 * _ecvt (MSVCRT.@)
855 char * CDECL _ecvt( double number, int ndigits, int *decpt, int *sign )
857 thread_data_t *data = msvcrt_get_thread_data();
858 char *dec;
860 if (!data->efcvt_buffer)
861 data->efcvt_buffer = MSVCRT_malloc( 80 ); /* ought to be enough */
863 snprintf(data->efcvt_buffer, 80, "%.*e", ndigits /* FIXME wrong */, number);
864 *sign = (number < 0);
865 dec = strchr(data->efcvt_buffer, '.');
866 *decpt = (dec) ? dec - data->efcvt_buffer : -1;
867 return data->efcvt_buffer;
870 /***********************************************************************
871 * _fcvt (MSVCRT.@)
873 char * CDECL _fcvt( double number, int ndigits, int *decpt, int *sign )
875 thread_data_t *data = msvcrt_get_thread_data();
876 char *dec;
878 if (!data->efcvt_buffer)
879 data->efcvt_buffer = MSVCRT_malloc( 80 ); /* ought to be enough */
881 snprintf(data->efcvt_buffer, 80, "%.*f", ndigits, number);
882 *sign = (number < 0);
883 dec = strchr(data->efcvt_buffer, '.');
884 if (dec)
886 *decpt = dec - data->efcvt_buffer;
887 while (*dec)
889 *dec =*(dec+1);
890 dec++;
893 else
894 *decpt = strlen(data->efcvt_buffer);
895 return data->efcvt_buffer;
898 /***********************************************************************
899 * _gcvt (MSVCRT.@)
901 * FIXME: uses both E and F.
903 char * CDECL _gcvt( double number, int ndigit, char *buff )
905 sprintf(buff, "%.*E", ndigit, number);
906 return buff;
909 #include <stdlib.h> /* div_t, ldiv_t */
911 /*********************************************************************
912 * div (MSVCRT.@)
913 * VERSION
914 * [i386] Windows binary compatible - returns the struct in eax/edx.
916 #ifdef __i386__
917 unsigned __int64 CDECL MSVCRT_div(int num, int denom)
919 div_t dt = div(num,denom);
920 return ((unsigned __int64)dt.rem << 32) | (unsigned int)dt.quot;
922 #else
923 /*********************************************************************
924 * div (MSVCRT.@)
925 * VERSION
926 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
928 MSVCRT_div_t CDECL MSVCRT_div(int num, int denom)
930 div_t dt = div(num,denom);
931 MSVCRT_div_t ret;
932 ret.quot = dt.quot;
933 ret.rem = dt.rem;
935 return ret;
938 #endif /* ifdef __i386__ */
941 /*********************************************************************
942 * ldiv (MSVCRT.@)
943 * VERSION
944 * [i386] Windows binary compatible - returns the struct in eax/edx.
946 #ifdef __i386__
947 unsigned __int64 CDECL MSVCRT_ldiv(long num, long denom)
949 ldiv_t ldt = ldiv(num,denom);
950 return ((unsigned __int64)ldt.rem << 32) | (unsigned long)ldt.quot;
952 #else
953 /*********************************************************************
954 * ldiv (MSVCRT.@)
955 * VERSION
956 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
958 MSVCRT_ldiv_t CDECL MSVCRT_ldiv(long num, long denom)
960 ldiv_t result = ldiv(num,denom);
962 MSVCRT_ldiv_t ret;
963 ret.quot = result.quot;
964 ret.rem = result.rem;
966 return ret;
968 #endif /* ifdef __i386__ */
970 /***********************************************************************
971 * _adj_fdiv_m16i (MSVCRT.@)
973 * NOTE
974 * I _think_ this function is intended to work around the Pentium
975 * fdiv bug.
977 void __stdcall _adj_fdiv_m16i( short arg )
979 TRACE("(): stub\n");
982 /***********************************************************************
983 * _adj_fdiv_m32 (MSVCRT.@)
985 * NOTE
986 * I _think_ this function is intended to work around the Pentium
987 * fdiv bug.
989 void __stdcall _adj_fdiv_m32( unsigned int arg )
991 TRACE("(): stub\n");
994 /***********************************************************************
995 * _adj_fdiv_m32i (MSVCRT.@)
997 * NOTE
998 * I _think_ this function is intended to work around the Pentium
999 * fdiv bug.
1001 void __stdcall _adj_fdiv_m32i( int arg )
1003 TRACE("(): stub\n");
1006 /***********************************************************************
1007 * _adj_fdiv_m64 (MSVCRT.@)
1009 * NOTE
1010 * I _think_ this function is intended to work around the Pentium
1011 * fdiv bug.
1013 void __stdcall _adj_fdiv_m64( unsigned __int64 arg )
1015 TRACE("(): stub\n");
1018 /***********************************************************************
1019 * _adj_fdiv_r (MSVCRT.@)
1020 * FIXME
1021 * This function is likely to have the wrong number of arguments.
1023 * NOTE
1024 * I _think_ this function is intended to work around the Pentium
1025 * fdiv bug.
1027 void _adj_fdiv_r(void)
1029 TRACE("(): stub\n");
1032 /***********************************************************************
1033 * _adj_fdivr_m16i (MSVCRT.@)
1035 * NOTE
1036 * I _think_ this function is intended to work around the Pentium
1037 * fdiv bug.
1039 void __stdcall _adj_fdivr_m16i( short arg )
1041 TRACE("(): stub\n");
1044 /***********************************************************************
1045 * _adj_fdivr_m32 (MSVCRT.@)
1047 * NOTE
1048 * I _think_ this function is intended to work around the Pentium
1049 * fdiv bug.
1051 void __stdcall _adj_fdivr_m32( unsigned int arg )
1053 TRACE("(): stub\n");
1056 /***********************************************************************
1057 * _adj_fdivr_m32i (MSVCRT.@)
1059 * NOTE
1060 * I _think_ this function is intended to work around the Pentium
1061 * fdiv bug.
1063 void __stdcall _adj_fdivr_m32i( int arg )
1065 TRACE("(): stub\n");
1068 /***********************************************************************
1069 * _adj_fdivr_m64 (MSVCRT.@)
1071 * NOTE
1072 * I _think_ this function is intended to work around the Pentium
1073 * fdiv bug.
1075 void __stdcall _adj_fdivr_m64( unsigned __int64 arg )
1077 TRACE("(): stub\n");
1080 /***********************************************************************
1081 * _adj_fpatan (MSVCRT.@)
1082 * FIXME
1083 * This function is likely to have the wrong number of arguments.
1085 * NOTE
1086 * I _think_ this function is intended to work around the Pentium
1087 * fdiv bug.
1089 void _adj_fpatan(void)
1091 TRACE("(): stub\n");
1094 /***********************************************************************
1095 * _adj_fprem (MSVCRT.@)
1096 * FIXME
1097 * This function is likely to have the wrong number of arguments.
1099 * NOTE
1100 * I _think_ this function is intended to work around the Pentium
1101 * fdiv bug.
1103 void _adj_fprem(void)
1105 TRACE("(): stub\n");
1108 /***********************************************************************
1109 * _adj_fprem1 (MSVCRT.@)
1110 * FIXME
1111 * This function is likely to have the wrong number of arguments.
1113 * NOTE
1114 * I _think_ this function is intended to work around the Pentium
1115 * fdiv bug.
1117 void _adj_fprem1(void)
1119 TRACE("(): stub\n");
1122 /***********************************************************************
1123 * _adj_fptan (MSVCRT.@)
1124 * FIXME
1125 * This function is likely to have the wrong number of arguments.
1127 * NOTE
1128 * I _think_ this function is intended to work around the Pentium
1129 * fdiv bug.
1131 void _adj_fptan(void)
1133 TRACE("(): stub\n");
1136 /***********************************************************************
1137 * _adjust_fdiv (MSVCRT.@)
1138 * FIXME
1139 * I _think_ this function should be a variable indicating whether
1140 * Pentium fdiv bug safe code should be used.
1142 void _adjust_fdiv(void)
1144 TRACE("(): stub\n");
1147 /***********************************************************************
1148 * _safe_fdiv (MSVCRT.@)
1149 * FIXME
1150 * This function is likely to have the wrong number of arguments.
1152 * NOTE
1153 * I _think_ this function is intended to work around the Pentium
1154 * fdiv bug.
1156 void _safe_fdiv(void)
1158 TRACE("(): stub\n");
1161 /***********************************************************************
1162 * _safe_fdivr (MSVCRT.@)
1163 * FIXME
1164 * This function is likely to have the wrong number of arguments.
1166 * NOTE
1167 * I _think_ this function is intended to work around the Pentium
1168 * fdiv bug.
1170 void _safe_fdivr(void)
1172 TRACE("(): stub\n");
1175 /***********************************************************************
1176 * _safe_fprem (MSVCRT.@)
1177 * FIXME
1178 * This function is likely to have the wrong number of arguments.
1180 * NOTE
1181 * I _think_ this function is intended to work around the Pentium
1182 * fdiv bug.
1184 void _safe_fprem(void)
1186 TRACE("(): stub\n");
1189 /***********************************************************************
1190 * _safe_fprem1 (MSVCRT.@)
1192 * FIXME
1193 * This function is likely to have the wrong number of arguments.
1195 * NOTE
1196 * I _think_ this function is intended to work around the Pentium
1197 * fdiv bug.
1199 void _safe_fprem1(void)
1201 TRACE("(): stub\n");