/src/lib/numeric/real_32.e

http://github.com/tybor/Liberty · Specman e · 118 lines · 72 code · 19 blank · 27 comment · 1 complexity · 55c62ca8e43f5f3db01816f7b95f4f94 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. expanded class REAL_32
  5. insert
  6. REAL_GENERAL
  7. feature {ANY} -- Conversions:
  8. to_real_64: REAL_64
  9. -- Explicit conversion to REAL_64.
  10. do
  11. Result := Current
  12. ensure
  13. Current = Result
  14. end
  15. to_real_extended: REAL_EXTENDED
  16. -- Explicit conversion to REAL_EXTENDED.
  17. do
  18. Result := Current
  19. ensure
  20. Current = Result
  21. end
  22. to_real_80: REAL_80
  23. -- Explicit conversion to REAL_80.
  24. do
  25. Result := Current
  26. ensure
  27. Current = Result
  28. end
  29. to_real_128: REAL_128
  30. -- Explicit conversion to REAL_128.
  31. do
  32. Result := Current
  33. ensure
  34. Current = Result
  35. end
  36. force_to_integer_64: INTEGER_64
  37. external "built_in"
  38. end
  39. force_to_integer_32: INTEGER_32
  40. external "built_in"
  41. end
  42. force_to_integer_16: INTEGER_16
  43. external "built_in"
  44. end
  45. force_to_natural_64: NATURAL_64
  46. external "built_in"
  47. end
  48. force_to_natural_32: NATURAL_32
  49. external "built_in"
  50. end
  51. force_to_natural_16: NATURAL_16
  52. external "built_in"
  53. end
  54. feature {ANY}
  55. zero: REAL_32 {REAL_32 0.0}
  56. one: REAL_32 {REAL_32 1.0}
  57. infix "~=" (other: like Current): BOOLEAN
  58. do
  59. Result := (Current - other).abs * ({REAL_32 2.0} ^ (mantissa_bits - precision)) <= Current.abs
  60. end
  61. hash_code: INTEGER
  62. do
  63. Result := force_to_integer_32
  64. if Result < 0 then
  65. Result := -(Result + 1)
  66. end
  67. end
  68. mantissa_bits: INTEGER_8 23
  69. exponent_bits: INTEGER_8 8
  70. feature {}
  71. sprintf (buffer: NATIVE_ARRAY[CHARACTER]; mode: CHARACTER; f: INTEGER; value: REAL_64)
  72. external "plug_in"
  73. alias "{
  74. location: "${sys}/runtime"
  75. module_name: "basic_sprintf"
  76. feature_name: "sprintf_real_64"
  77. }"
  78. end
  79. end -- class REAL_32
  80. --
  81. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  82. --
  83. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  84. -- of this software and associated documentation files (the "Software"), to deal
  85. -- in the Software without restriction, including without limitation the rights
  86. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  87. -- copies of the Software, and to permit persons to whom the Software is
  88. -- furnished to do so, subject to the following conditions:
  89. --
  90. -- The above copyright notice and this permission notice shall be included in
  91. -- all copies or substantial portions of the Software.
  92. --
  93. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  94. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  95. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  96. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  97. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  98. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  99. -- THE SOFTWARE.