Leaked source code of windows server 2003
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.

56 lines
1.4 KiB

  1. /***
  2. *frexp.c - get mantissa and exponent of a floating point number
  3. *
  4. * Copyright (c) 1991-2001, 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. * 02-06-95 JWM Mac merge
  12. *
  13. *******************************************************************************/
  14. #include <math.h>
  15. #include <trans.h>
  16. /***
  17. *double frexp(double x, double *expptr)
  18. *
  19. *Purpose:
  20. * The nomalized fraction f is returned: .5<=f<1
  21. * The exponent is stored in the object pointed by expptr
  22. *
  23. *Entry:
  24. *
  25. *Exit:
  26. *
  27. *Exceptions:
  28. * NAN: domain error
  29. *
  30. *******************************************************************************/
  31. double frexp(double x, int *expptr)
  32. {
  33. uintptr_t savedcw;
  34. double man;
  35. /* save user fp control word */
  36. savedcw = _maskfp();
  37. /* check for infinity or NAN */
  38. if (IS_D_SPECIAL(x)){
  39. *expptr = INT_NAN;
  40. switch (_sptype(x)) {
  41. case T_PINF:
  42. case T_NINF:
  43. return _except1(FP_I, OP_FREXP, x, QNAN_FREXP, savedcw);
  44. case T_QNAN:
  45. return _handle_qnan1(OP_FREXP, x, savedcw);
  46. default: //T_SNAN
  47. return _except1(FP_I, OP_FREXP, x, _s2qnan(x), savedcw);
  48. }
  49. }
  50. man = _decomp(x, expptr);
  51. RETURN(savedcw,man);
  52. }