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.

67 lines
1.5 KiB

  1. /***
  2. *fabs.c - absolute value 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. * 12-10-91 GDP Domain error for NAN, use fp negation
  11. * 1-13-91 GDP support IEEE exceptions
  12. * 6-23-92 GDP fabs(-0) is now +0 (NCEG spec)
  13. * 02-06-95 JWM Mac merge
  14. * 10-07-97 RDL Added IA64.
  15. * 05-17-99 PML Remove all Macintosh support.
  16. * 07-15-01 PML Remove all ALPHA, MIPS, and PPC code
  17. *
  18. *******************************************************************************/
  19. #include <math.h>
  20. #include <trans.h>
  21. #if defined(_M_IX86) || defined(_M_IA64)
  22. #pragma function(fabs)
  23. #endif
  24. /***
  25. *double fabs(double x)
  26. *
  27. *Purpose:
  28. * Compute |x|
  29. *
  30. *Entry:
  31. *
  32. *Exit:
  33. *
  34. *Exceptions:
  35. * I
  36. *
  37. *******************************************************************************/
  38. double fabs(double x)
  39. {
  40. uintptr_t savedcw;
  41. double result;
  42. /* save user fp control word */
  43. savedcw = _maskfp();
  44. if (IS_D_SPECIAL(x)){
  45. switch (_sptype(x)) {
  46. case T_PINF:
  47. RETURN(savedcw,x);
  48. case T_NINF:
  49. RETURN(savedcw,-x);
  50. case T_QNAN:
  51. return _handle_qnan1(OP_ABS, x, savedcw);
  52. default: //T_SNAN
  53. return _except1(FP_I, OP_ABS, x, _s2qnan(x), savedcw);
  54. }
  55. }
  56. *D_HI(result) = *D_HI(x) & ~(1<<31);
  57. *D_LO(result) = *D_LO(x);
  58. RETURN(savedcw,result);
  59. }