Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
1.8 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. modf.c
  5. Abstract:
  6. modf() function
  7. Author:
  8. Revision History:
  9. 29-sept-1999 ATM Shafiqul Khalid [askhalid] copied from rtl library.
  10. --*/
  11. #include <math.h>
  12. #include <trans.h>
  13. #include <float.h>
  14. extern double _frnd(double);
  15. extern double _copysign (double x, double y);
  16. /***
  17. *double modf(double x, double *intptr)
  18. *
  19. *Purpose:
  20. * Split x into fractional and integer part
  21. * The signed fractional portion is returned
  22. * The integer portion is stored as a floating point value at intptr
  23. *
  24. *Entry:
  25. *
  26. *Exit:
  27. *
  28. *Exceptions:
  29. * I
  30. *******************************************************************************/
  31. static unsigned int newcw = (ICW & ~IMCW_RC) | (IRC_CHOP & IMCW_RC);
  32. double modf(double x, double *intptr)
  33. {
  34. unsigned int savedcw;
  35. double result,intpart;
  36. /* save user fp control word */
  37. savedcw = _ctrlfp(0, 0); /* get old control word */
  38. _ctrlfp(newcw,IMCW); /* round towards 0 */
  39. /* check for infinity or NAN */
  40. if (IS_D_SPECIAL(x)){
  41. *intptr = QNAN_MODF;
  42. switch (_sptype(x)) {
  43. case T_PINF:
  44. case T_NINF:
  45. *intptr = x;
  46. result = _copysign(0, x);
  47. RETURN(savedcw,result);
  48. case T_QNAN:
  49. *intptr = x;
  50. return _handle_qnan1(OP_MODF, x, savedcw);
  51. default: //T_SNAN
  52. result = _s2qnan(x);
  53. *intptr = result;
  54. return _except1(FP_I, OP_MODF, x, result, savedcw);
  55. }
  56. }
  57. if (x == 0.0) {
  58. *intptr = x;
  59. result = x;
  60. }
  61. else {
  62. intpart = _frnd(x); //fix needed: this may set the P exception flag
  63. //and pollute the fp status word
  64. *intptr = intpart;
  65. result = x - intpart;
  66. }
  67. RETURN(savedcw,result);
  68. }