/src/lib/numeric/integer_64.e

http://github.com/tybor/Liberty · Specman e · 268 lines · 188 code · 34 blank · 46 comment · 7 complexity · 7598fb68d48fa0accb4994108ff5b3db 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 INTEGER_64
  5. insert
  6. INTEGER_GENERAL
  7. feature {ANY} -- Conversions:
  8. fit_integer_8: BOOLEAN
  9. -- Does `Current' fit in INTEGER_8?
  10. do
  11. if Current >= -128 then
  12. Result := Current <= 127
  13. end
  14. ensure
  15. Result = Current.in_range(-128, 127)
  16. end
  17. to_integer_8: INTEGER_8
  18. -- Explicit conversion to INTEGER_8.
  19. require
  20. fit_integer_8
  21. external "built_in"
  22. ensure
  23. Current.is_equal(Result)
  24. end
  25. fit_integer_16: BOOLEAN
  26. -- Does `Current' fit in INTEGER_16?
  27. do
  28. if Current >= -32768 then
  29. Result := Current <= 32767
  30. end
  31. ensure
  32. Result = Current.in_range(-32768, 32767)
  33. end
  34. to_integer_16: INTEGER_16
  35. -- Explicit conversion to INTEGER_16.
  36. require
  37. fit_integer_16
  38. external "built_in"
  39. ensure
  40. Current.is_equal(Result)
  41. end
  42. fit_integer_32: BOOLEAN
  43. -- Does `Current' fit in INTEGER_32?
  44. do
  45. if Current >= -2147483648 then
  46. Result := Current <= 2147483647
  47. end
  48. ensure
  49. Result = Current.in_range(-2147483648, 2147483647)
  50. end
  51. to_integer_32: INTEGER_32
  52. -- Explicit conversion to INTEGER_32.
  53. require
  54. fit_integer_32
  55. external "built_in"
  56. ensure
  57. Current = Result
  58. end
  59. fit_natural_8: BOOLEAN
  60. -- Does `Current' fit in NATURAL_8?
  61. do
  62. if Current >= 0 then
  63. Result := Current <= 255
  64. end
  65. ensure
  66. Result = Current.in_range(0, 255)
  67. end
  68. to_natural_8: NATURAL_8
  69. -- Explicit conversion to NATURAL_8.
  70. require
  71. fit_natural_8
  72. external "built_in"
  73. ensure
  74. Result.to_integer_16 = Current
  75. end
  76. fit_natural_16: BOOLEAN
  77. -- Does `Current' fit in NATURAL_16?
  78. do
  79. if Current >= 0 then
  80. Result := Current <= 65535
  81. end
  82. ensure
  83. Result = Current.in_range(0, 65535)
  84. end
  85. to_natural_16: NATURAL_16
  86. -- Explicit conversion to NATURAL_16.
  87. require
  88. fit_natural_16
  89. external "built_in"
  90. ensure
  91. Result.to_integer_32 = Current
  92. end
  93. fit_natural_32: BOOLEAN
  94. -- Does `Current' fit in NATURAL_32?
  95. do
  96. if Current >= 0 then
  97. Result := Current <= 4294967295
  98. end
  99. ensure
  100. Result = Current.in_range(0, 4294967295)
  101. end
  102. to_natural_32: NATURAL_32
  103. -- Explicit conversion to NATURAL_32.
  104. require
  105. fit_natural_32
  106. external "built_in"
  107. ensure
  108. Result.to_integer_64 = Current
  109. end
  110. to_natural_64: NATURAL_64
  111. -- Explicit conversion to NATURAL_64.
  112. require
  113. Current >= 0
  114. external "built_in"
  115. ensure
  116. Result.to_integer_64 = Current
  117. end
  118. force_to_real_32: REAL_32
  119. -- Forced conversion to REAL_32 (possible loss of precision).
  120. -- (See also `fit_real_32' and `to_real_32'.)
  121. external "built_in"
  122. end
  123. fit_real_32: BOOLEAN
  124. -- Does `Current' fit in REAL_32?
  125. do
  126. Result := fit_integer_32 and then to_integer_32.fit_real_32
  127. end
  128. to_real_32: REAL_32
  129. -- Explicit conversion to REAL_32. (See also `force_to_real_32'.)
  130. require
  131. fit_real_32
  132. do
  133. Result := force_to_real_32
  134. ensure
  135. Result.force_to_integer_64 = Current
  136. end
  137. force_to_real_64: REAL_64
  138. -- Forced conversion to REAL_64 (possible loss of precision).
  139. -- (See also `fit_real_64' and `to_real_64'.)
  140. external "built_in"
  141. end
  142. fit_real_64: BOOLEAN
  143. -- Does `Current' fit in REAL_64?
  144. do
  145. Result := integer_64_fit_real_64(Current)
  146. end
  147. to_real_64: REAL_64
  148. -- Explicit conversion to REAL_64. (See also `force_to_real_64'.)
  149. require
  150. fit_real_64
  151. do
  152. Result := force_to_real_64
  153. ensure
  154. Result.force_to_integer_64 = Current
  155. end
  156. to_number: NUMBER
  157. local
  158. number_tools: NUMBER_TOOLS
  159. do
  160. Result := number_tools.from_integer_64(Current)
  161. ensure then
  162. Result @= Current
  163. end
  164. decimal_digit: CHARACTER
  165. do
  166. Result := (Current.to_integer_32 + '0'.code).to_character
  167. end
  168. hexadecimal_digit: CHARACTER
  169. do
  170. if Current <= 9 then
  171. Result := (to_integer_8 + '0'.code).to_character
  172. else
  173. Result := ('A'.code + (to_integer_8 - 10)).to_character
  174. end
  175. end
  176. feature {ANY}
  177. low_32: INTEGER_32
  178. -- The 32 low bits of `Current' (i.e. the right-most part).
  179. external "built_in"
  180. end
  181. high_32: INTEGER_32
  182. -- The 32 high bits of `Current' (i.e. the left-most part).
  183. do
  184. Result := (Current |>> 32).low_32
  185. end
  186. one: INTEGER_8 1
  187. zero: INTEGER_8 0
  188. hash_code: INTEGER
  189. do
  190. Result := Current.low_32 & 0x7FFFFFFF
  191. end
  192. sqrt: REAL
  193. do
  194. Result := force_to_real_64.sqrt
  195. end
  196. log: REAL
  197. do
  198. Result := force_to_real_64.log
  199. end
  200. log10: REAL
  201. do
  202. Result := force_to_real_64.log10
  203. end
  204. bit_count: INTEGER_8 64
  205. feature {}
  206. integer_64_fit_real_64 (integer_64: INTEGER_64): BOOLEAN
  207. external "plug_in"
  208. alias "{
  209. location: "${sys}/runtime"
  210. module_name: "integer_fit_real"
  211. feature_name: "integer_64_fit_real_64"
  212. }"
  213. end
  214. end -- class INTEGER_64
  215. --
  216. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  217. --
  218. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  219. -- of this software and associated documentation files (the "Software"), to deal
  220. -- in the Software without restriction, including without limitation the rights
  221. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  222. -- copies of the Software, and to permit persons to whom the Software is
  223. -- furnished to do so, subject to the following conditions:
  224. --
  225. -- The above copyright notice and this permission notice shall be included in
  226. -- all copies or substantial portions of the Software.
  227. --
  228. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  229. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  230. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  231. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  232. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  233. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  234. -- THE SOFTWARE.