Windows NT 4.0 source code leak
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.

64 lines
1.4 KiB

4 years ago
  1. /***
  2. *modf.c - modf()
  3. *
  4. * Copyright (c) 1991-1991, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *
  8. *Revision History:
  9. * 8-24-91 GDP written
  10. * 1-13-92 GDP support IEEE exceptions
  11. *
  12. *******************************************************************************/
  13. #include <math.h>
  14. #include <trans.h>
  15. extern double _frnd(double);
  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(newcw,IMCW); /* round towards 0 */
  38. /* check for infinity or NAN */
  39. if (IS_D_SPECIAL(x)){
  40. *intptr = QNAN_MODF;
  41. switch (_sptype(x)) {
  42. case T_PINF:
  43. case T_NINF:
  44. return _except1(FP_I, OP_MODF, x, QNAN_MODF, savedcw);
  45. case T_QNAN:
  46. return _handle_qnan1(OP_MODF, x, savedcw);
  47. default: //T_SNAN
  48. return _except1(FP_I, OP_MODF, x, _s2qnan(x), savedcw);
  49. }
  50. }
  51. intpart = _frnd(x); //fix needed: this may set the P exception flag
  52. //and pollute the fp status word
  53. *intptr = intpart;
  54. result = x - intpart;
  55. RETURN(savedcw,result);
  56. }