Changeset 10005 for trunk/src/msvcrt/math.c
- Timestamp:
- Apr 10, 2003, 12:28:07 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/msvcrt/math.c
r9633 r10005 20 20 #ifdef __WIN32OS2__ 21 21 #include <emxheader.h> 22 #include <stdlib.h> 23 #include <string.h> 24 #include <math.h> 25 extern double logb(double); 26 extern double scalb(double,double); 22 27 #else 23 28 #include "config.h" … … 29 34 #define __USE_ISOC9X 1 30 35 #define __USE_ISOC99 1 31 #include <math.h> 36 32 37 #ifdef HAVE_IEEEFP_H 33 38 #include <ieeefp.h> … … 43 48 #ifndef finite /* Could be a macro */ 44 49 #ifdef isfinite 45 #define finite(x) isfinite(x) 50 #define finite(x) isfinite(x) 46 51 #else 47 52 #define finite(x) (!isnan(x)) /* At least catch some cases */ … … 135 140 { 136 141 FPU_DOUBLE(x); 142 dprintf(("MSVCRT: _CIacos")); 137 143 if (x < -1.0 || x > 1.0 || !finite(x)) *MSVCRT__errno() = MSVCRT_EDOM; 138 144 return acos(x); … … 145 151 { 146 152 FPU_DOUBLE(x); 153 dprintf(("MSVCRT: _CIacos")); 147 154 if (x < -1.0 || x > 1.0 || !finite(x)) *MSVCRT__errno() = MSVCRT_EDOM; 148 155 return asin(x); … … 155 162 { 156 163 FPU_DOUBLE(x); 164 dprintf(("MSVCRT: _CIacos")); 157 165 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM; 158 166 return atan(x); … … 165 173 { 166 174 FPU_DOUBLES(x,y); 175 dprintf(("MSVCRT: _CIacos")); 167 176 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM; 168 177 return atan2(x,y); … … 175 184 { 176 185 FPU_DOUBLE(x); 186 dprintf(("MSVCRT: _CIacos")); 177 187 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM; 178 188 return cos(x); … … 185 195 { 186 196 FPU_DOUBLE(x); 197 dprintf(("MSVCRT: _CIacos")); 187 198 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM; 188 199 return cosh(x); … … 195 206 { 196 207 FPU_DOUBLE(x); 208 dprintf(("MSVCRT: _CIacos")); 197 209 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM; 198 210 return exp(x); … … 205 217 { 206 218 FPU_DOUBLES(x,y); 207 if (!finite(x) || !finite(y)) *MSVCRT__errno() = MSVCRT_EDOM; 219 dprintf(("MSVCRT: _CIfmod %f %f",x,y)); 220 if (!finite(x) || !finite(y)) { *MSVCRT__errno() = MSVCRT_EDOM; dprintf(("ERROR!")); } 221 dprintf(("MSVCRT: _CIfmod returning %f",fmod(x,y))); 208 222 return fmod(x,y); 209 223 } … … 215 229 { 216 230 FPU_DOUBLE(x); 231 dprintf(("MSVCRT: _CIacos")); 217 232 if (x < 0.0 || !finite(x)) *MSVCRT__errno() = MSVCRT_EDOM; 218 233 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE; … … 226 241 { 227 242 FPU_DOUBLE(x); 243 dprintf(("MSVCRT: _CIacos")); 228 244 if (x < 0.0 || !finite(x)) *MSVCRT__errno() = MSVCRT_EDOM; 229 245 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE; … … 238 254 double z; 239 255 FPU_DOUBLES(x,y); 256 dprintf(("MSVCRT: _CIacos")); 240 257 /* FIXME: If x < 0 and y is not integral, set EDOM */ 241 258 z = pow(x,y); … … 250 267 { 251 268 FPU_DOUBLE(x); 269 dprintf(("MSVCRT: _CIacos")); 252 270 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM; 253 271 return sin(x); … … 260 278 { 261 279 FPU_DOUBLE(x); 280 dprintf(("MSVCRT: _CIacos")); 262 281 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM; 263 282 return sinh(x); … … 270 289 { 271 290 FPU_DOUBLE(x); 291 dprintf(("MSVCRT: _CIacos")); 272 292 if (x < 0.0 || !finite(x)) *MSVCRT__errno() = MSVCRT_EDOM; 273 293 return sqrt(x); … … 280 300 { 281 301 FPU_DOUBLE(x); 302 dprintf(("MSVCRT: _CIacos")); 282 303 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM; 283 304 return tan(x); … … 290 311 { 291 312 FPU_DOUBLE(x); 313 dprintf(("MSVCRT: _CIacos")); 292 314 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM; 293 315 return tanh(x); … … 324 346 int _fpclass(double num) 325 347 { 348 dprintf(("MSVCRT: _fpclass")); 326 349 #if defined(HAVE_FPCLASS) || defined(fpclass) 327 350 switch (fpclass( num )) … … 358 381 * _rotl (MSVCRT.@) 359 382 */ 360 unsigned int _rotl(unsigned int num, int shift)383 unsigned int MSVCRT__rotl(unsigned int num, int shift) 361 384 { 362 385 shift &= 31; … … 369 392 double _logb(double num) 370 393 { 394 dprintf(("MSVCRT: _logb")); 371 395 if (!finite(num)) *MSVCRT__errno() = MSVCRT_EDOM; 372 396 return logb(num); … … 376 400 * _lrotl (MSVCRT.@) 377 401 */ 378 unsigned long _lrotl(unsigned long num, int shift) 379 { 402 unsigned long MSVCRT__lrotl(unsigned long num, int shift) 403 { 404 dprintf(("MSVCRT: _lrotl")); 380 405 shift &= 0x1f; 381 406 return (num << shift) | (num >> (32-shift)); … … 385 410 * _lrotr (MSVCRT.@) 386 411 */ 387 unsigned long _lrotr(unsigned long num, int shift) 388 { 412 unsigned long MSVCRT__lrotr(unsigned long num, int shift) 413 { 414 dprintf(("MSVCRT: _lrotr")); 389 415 shift &= 0x1f; 390 416 return (num >> shift) | (num << (32-shift)); … … 394 420 * _rotr (MSVCRT.@) 395 421 */ 396 unsigned int _rotr(unsigned int num, int shift) 397 { 422 unsigned int MSVCRT__rotr(unsigned int num, int shift) 423 { 424 dprintf(("MSVCRT: _rotr")); 398 425 shift &= 0x1f; 399 426 return (num >> shift) | (num << (32-shift)); … … 406 433 { 407 434 /* Note - Can't forward directly as libc expects y as double */ 435 dprintf(("MSVCRT: _scalb")); 408 436 double dblpower = (double)power; 409 437 if (!finite(num)) *MSVCRT__errno() = MSVCRT_EDOM; … … 414 442 * _matherr (MSVCRT.@) 415 443 */ 416 int _matherr(MSVCRT_exception *e)444 int MSVCRT__matherr(MSVCRT_exception *e) 417 445 { 418 446 if (e) … … 478 506 { 479 507 double z = ldexp(num,exp); 480 508 dprintf(("MSVCRT: ldexpp")); 481 509 if (!finite(z)) 482 510 *MSVCRT__errno() = MSVCRT_ERANGE; … … 489 517 * _cabs (MSVCRT.@) 490 518 */ 491 double _cabs(MSVCRT_complex num) 492 { 519 double MSVCRT__cabs(MSVCRT_complex num) 520 { 521 dprintf(("MSVCRT: _cabs")); 493 522 return sqrt(num.real * num.real + num.imaginary * num.imaginary); 494 523 } … … 499 528 double _chgsign(double num) 500 529 { 530 dprintf(("MSVCRT: _chgsign")); 501 531 /* FIXME: +-infinity,Nan not tested */ 502 532 return -num; … … 506 536 * _control87 (MSVCRT.@) 507 537 */ 508 unsigned int _control87(unsigned int newval, unsigned int mask)538 unsigned int MSVCRT__control87(unsigned int newval, unsigned int mask) 509 539 { 510 540 #if defined(__GNUC__) && defined(__i386__) … … 579 609 { 580 610 #ifdef __i386__ 581 return _control87( newval, mask & ~_EM_DENORMAL );611 return MSVCRT__control87( newval, mask & ~_EM_DENORMAL ); 582 612 #else 583 613 FIXME(":Not Implemented!\n"); … … 589 619 * _copysign (MSVCRT.@) 590 620 */ 591 double _copysign(double num, double sign) 592 { 621 double MSVCRT__copysign(double num, double sign) 622 { 623 dprintf(("MSVCRT: _CIacos")); 593 624 /* FIXME: Behaviour for Nan/Inf? */ 594 625 if (sign < 0.0) … … 602 633 int _finite(double num) 603 634 { 635 dprintf(("MSVCRT: _finite for %f returns %d",num, finite(num)?1:0)); 604 636 return (finite(num)?1:0); /* See comment for _isnan() */ 605 637 } … … 608 640 * _fpreset (MSVCRT.@) 609 641 */ 610 void _fpreset(void)642 void MSVCRT__fpreset(void) 611 643 { 612 644 #if defined(__GNUC__) && defined(__i386__) … … 625 657 * Do the same, as the result may be used in calculations 626 658 */ 659 dprintf(("MSVCRT: _isnan for %f returns %d",num, isnan(num)?1:0)); 627 660 return isnan(num) ? 1 : 0; 628 661 } … … 631 664 * _y0 (MSVCRT.@) 632 665 */ 633 double _y0(double num)666 double MSVCRT__y0(double num) 634 667 { 635 668 double retval; 669 dprintf(("MSVCRT: _CIacos")); 636 670 if (!finite(num)) *MSVCRT__errno() = MSVCRT_EDOM; 637 671 retval = y0(num); … … 647 681 * _y1 (MSVCRT.@) 648 682 */ 649 double _y1(double num)683 double MSVCRT__y1(double num) 650 684 { 651 685 double retval; 686 dprintf(("MSVCRT: _CIacos")); 652 687 if (!finite(num)) *MSVCRT__errno() = MSVCRT_EDOM; 653 688 retval = y1(num); … … 663 698 * _yn (MSVCRT.@) 664 699 */ 665 double _yn(int order, double num)700 double MSVCRT__yn(int order, double num) 666 701 { 667 702 double retval; 703 dprintf(("MSVCRT: _CIacos")); 668 704 if (!finite(num)) *MSVCRT__errno() = MSVCRT_EDOM; 669 705 retval = yn(order,num); … … 679 715 * _nextafter (MSVCRT.@) 680 716 */ 681 double _nextafter(double num, double next)717 double MSVCRT__nextafter(double num, double next) 682 718 { 683 719 double retval; 720 dprintf(("MSVCRT: _CIacos")); 684 721 if (!finite(num) || !finite(next)) *MSVCRT__errno() = MSVCRT_EDOM; 685 retval = nextafter(num,next);722 retval = MSVCRT__nextafter(num,next); 686 723 return retval; 724 } 725 726 /********************************************************************* 727 * _ecvt (MSVCRT.@) 728 */ 729 char *_ecvt( double number, int ndigits, int *decpt, int *sign ) 730 { 731 MSVCRT_thread_data *data = msvcrt_get_thread_data(); 732 char *dec; 733 734 if (!data->efcvt_buffer) 735 data->efcvt_buffer = MSVCRT_malloc( 80 ); /* ought to be enough */ 736 737 _snprintf(data->efcvt_buffer, 80, "%.*e", ndigits /* FIXME wrong */, number); 738 *sign = (number < 0); 739 dec = strchr(data->efcvt_buffer, '.'); 740 *decpt = (dec) ? dec - data->efcvt_buffer : -1; 741 return data->efcvt_buffer; 742 } 743 744 /*********************************************************************** 745 * _fcvt (MSVCRT.@) 746 */ 747 char *_fcvt( double number, int ndigits, int *decpt, int *sign ) 748 { 749 MSVCRT_thread_data *data = msvcrt_get_thread_data(); 750 char *dec; 751 752 if (!data->efcvt_buffer) 753 data->efcvt_buffer = MSVCRT_malloc( 80 ); /* ought to be enough */ 754 755 _snprintf(data->efcvt_buffer, 80, "%.*e", ndigits, number); 756 *sign = (number < 0); 757 dec = strchr(data->efcvt_buffer, '.'); 758 *decpt = (dec) ? dec - data->efcvt_buffer : -1; 759 return data->efcvt_buffer; 760 } 761 762 /*********************************************************************** 763 * _gcvt (MSVCRT.@) 764 * 765 * FIXME: uses both E and F. 766 */ 767 char *MSVCRT__gcvt( double number, int ndigit, char *buff ) 768 { 769 sprintf(buff, "%.*E", ndigit, number); 770 return buff; 687 771 } 688 772 … … 695 779 */ 696 780 #ifdef __i386__ 697 LONGLONGMSVCRT_div(int num, int denom)698 { 699 LONGLONGretval;781 long long MSVCRT_div(int num, int denom) 782 { 783 long long retval; 700 784 div_t dt = div(num,denom); 701 retval = ((LONGLONG)dt.rem << 32) | dt.quot; 785 dprintf(("MSVCRT: div")); 786 retval = ((long long)dt.rem << 32) | dt.quot; 702 787 return retval; 703 788 } … … 731 816 ULONGLONG retval; 732 817 ldiv_t ldt = ldiv(num,denom); 818 dprintf(("MSVCRT: ldiv")); 733 819 retval = ((ULONGLONG)ldt.rem << 32) | (ULONG)ldt.quot; 734 820 return retval; … … 1001 1087 TRACE("(): stub\n"); 1002 1088 } 1089 1090 1091 double MSVCRT_atof (__const__ char * str) 1092 { 1093 double res; 1094 res = atof(str); 1095 dprintf(("MSVCRT: _atof - convert %s - result %f",str,res)); 1096 return res; 1097 }
Note:
See TracChangeset
for help on using the changeset viewer.