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.

66 lines
1.4 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. *
  17. *******************************************************************************/
  18. #include <math.h>
  19. #include <trans.h>
  20. #if defined(_M_IX86) || defined(_M_PPC) || defined(_M_IA64)
  21. #pragma function(fabs)
  22. #endif
  23. /***
  24. *double fabs(double x)
  25. *
  26. *Purpose:
  27. * Compute |x|
  28. *
  29. *Entry:
  30. *
  31. *Exit:
  32. *
  33. *Exceptions:
  34. * I
  35. *
  36. *******************************************************************************/
  37. double fabs(double x)
  38. {
  39. uintptr_t savedcw;
  40. double result;
  41. /* save user fp control word */
  42. savedcw = _maskfp();
  43. if (IS_D_SPECIAL(x)){
  44. switch (_sptype(x)) {
  45. case T_PINF:
  46. RETURN(savedcw,x);
  47. case T_NINF:
  48. RETURN(savedcw,-x);
  49. case T_QNAN:
  50. return _handle_qnan1(OP_ABS, x, savedcw);
  51. default: //T_SNAN
  52. return _except1(FP_I, OP_ABS, x, _s2qnan(x), savedcw);
  53. }
  54. }
  55. *D_HI(result) = *D_HI(x) & ~(1<<31);
  56. *D_LO(result) = *D_LO(x);
  57. RETURN(savedcw,result);
  58. }