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.

89 lines
2.2 KiB

  1. // TITLE("Floating Point Round")
  2. //++
  3. //
  4. // Copyright (c) 1992 Digital Equipment Corporation
  5. //
  6. // Module Name:
  7. //
  8. // frnd.s
  9. //
  10. // Abstract:
  11. //
  12. // This module implements the floating round to integer function.
  13. //
  14. // Author:
  15. //
  16. // Thomas Van Baak (tvb) 07-Sep-1992
  17. //
  18. // Environment:
  19. //
  20. // Any mode.
  21. //
  22. // Revision History:
  23. //
  24. //--
  25. #include "ksalpha.h"
  26. SBTTL("Floating Round to Integer")
  27. //++
  28. //
  29. // DOUBLE
  30. // _frnd (
  31. // IN DOUBLE x
  32. // )
  33. //
  34. // Routine Description:
  35. //
  36. // This function rounds the given finite floating point argument to
  37. // an integer using nearest rounding.
  38. //
  39. // Arguments:
  40. //
  41. // x (f16) - Supplies the floating point value to be rounded.
  42. //
  43. // Return Value:
  44. //
  45. // The integer rounded floating point value is returned in f0.
  46. //
  47. // Implementation Notes:
  48. //
  49. //--
  50. LEAF_ENTRY(_frnd)
  51. //
  52. // If the absolute value of the argument is greater than or equal to 2^52,
  53. // then the argument is already an integer and it can be returned as the
  54. // function value. Note that 2^52 - 1 is the largest integer representable
  55. // by T-format (double) floating point because the mantissa (without the
  56. // hidden bit) is 52 bits wide.
  57. //
  58. fbeq f16, 10f // return if argument is 0.0
  59. ldt f10, Two52 // get 2^52 magic constant
  60. fabs f16, f11 // get absolute value of argument
  61. cmptlt f10, f11, f12 // is 2^52 < arg?
  62. fbeq f12, 20f // if eq[false], then do rounding
  63. 10: cpys f16, f16, f0 // argument is return value
  64. ret zero, (ra) // return
  65. 20: cpys f16, f10, f10 // if argument < 0, use -2^52 instead
  66. addt f16, f10, f0 // add [+-]2^52 (nearest rounding)
  67. subt f0, f10, f0 // subtract [+-]2^52 (nearest rounding)
  68. ret zero, (ra) // return
  69. .end _frnd
  70. //
  71. // Define floating point constants.
  72. //
  73. // (avoid ldit with floating point literal due to bug in acc/as that
  74. // creates writable .rdata sections - tvb)
  75. //
  76. .align 3
  77. .rdata
  78. Two52:
  79. .double 4503599627370496.0 // 2^52