/src/lib/numeric/natural_16.e

http://github.com/tybor/Liberty · Specman e · 189 lines · 128 code · 26 blank · 35 comment · 0 complexity · 9de75148cf74f45c68808d164b5dcb53 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 NATURAL_16
  5. insert
  6. NATURAL_GENERAL
  7. redefine infix "//", infix "\\"
  8. end
  9. feature {ANY} -- Explicit conversions:
  10. fit_natural_8: BOOLEAN
  11. -- Does `Current' fit in NATURAL_8?
  12. do
  13. Result := Current <= 255.to_natural_16
  14. ensure
  15. Result = (Current <= 255.to_natural_16)
  16. end
  17. to_natural_8: NATURAL_8
  18. -- Explicit conversion to NATURAL_8.
  19. require
  20. fit_natural_8
  21. external "built_in"
  22. ensure
  23. Result.to_natural_16 = Current
  24. end
  25. to_natural_32: NATURAL_32
  26. -- Explicit conversion to NATURAL_32.
  27. external "built_in"
  28. ensure
  29. Result.to_natural_16 = Current
  30. end
  31. to_natural_64: NATURAL_64
  32. -- Explicit conversion to NATURAL_64.
  33. external "built_in"
  34. ensure
  35. Result.to_natural_16 = Current
  36. end
  37. fit_integer_8: BOOLEAN
  38. -- Does `Current' fit in INTEGER_8?
  39. do
  40. Result := Current <= 127.to_natural_16
  41. ensure
  42. Result = (Current <= 127.to_natural_16)
  43. end
  44. to_integer_8: INTEGER_8
  45. -- Explicit conversion to INTEGER_8.
  46. require
  47. fit_integer_8
  48. external "built_in"
  49. ensure
  50. Result.to_natural_16 = Current
  51. end
  52. fit_integer_16: BOOLEAN
  53. -- Does `Current' fit in INTEGER_16?
  54. do
  55. Result := Current <= 32767.to_natural_16
  56. ensure
  57. Result = (Current <= 32767.to_natural_16)
  58. end
  59. to_integer_16: INTEGER_16
  60. -- Explicit conversion to INTEGER_16.
  61. require
  62. fit_integer_16
  63. external "built_in"
  64. ensure
  65. Result.to_natural_16 = Current
  66. end
  67. to_integer_32: INTEGER_32
  68. -- Explicit conversion to INTEGER_32.
  69. external "built_in"
  70. ensure
  71. Result.to_natural_16 = Current
  72. end
  73. to_integer_64: INTEGER_64
  74. -- Explicit conversion to INTEGER_64.
  75. external "built_in"
  76. ensure
  77. Result.to_natural_16 = Current
  78. end
  79. to_real_32: REAL_32
  80. -- Explicit conversion to REAL_32.
  81. do
  82. Result := to_integer_32.force_to_real_32
  83. end
  84. to_real_64: REAL_64
  85. -- Explicit conversion to REAL_64.
  86. do
  87. Result := to_integer_32
  88. end
  89. feature {ANY}
  90. infix "//" (other: like Current): like Current
  91. require
  92. other /= 0.to_natural_16
  93. external "built_in"
  94. end
  95. infix "\\" (other: like Current): like Current
  96. require
  97. other /= 0.to_natural_16
  98. external "built_in"
  99. end
  100. is_odd: BOOLEAN
  101. do
  102. Result := to_integer_32.is_odd
  103. end
  104. is_even: BOOLEAN
  105. do
  106. Result := to_integer_32.is_even
  107. end
  108. hash_code: INTEGER
  109. do
  110. Result := to_integer_32
  111. end
  112. append_in (buffer: STRING)
  113. do
  114. to_integer_32.append_in(buffer)
  115. end
  116. append_in_unicode (buffer: UNICODE_STRING)
  117. do
  118. to_integer_32.append_in_unicode(buffer)
  119. end
  120. decimal_digit: CHARACTER
  121. require
  122. in_range(0.to_natural_16, 9.to_natural_16)
  123. do
  124. Result := to_integer_8.hexadecimal_digit
  125. end
  126. hexadecimal_digit: CHARACTER
  127. require
  128. in_range(0.to_natural_16, 15.to_natural_16)
  129. do
  130. Result := to_integer_8.hexadecimal_digit
  131. end
  132. to_character: CHARACTER
  133. require
  134. to_integer_16 <= Maximum_character_code
  135. do
  136. Result := to_integer_16.to_character
  137. end
  138. to_number: NUMBER
  139. do
  140. Result := to_integer_32.to_number
  141. end
  142. bit_count: INTEGER_8 16
  143. end -- NATURAL_16
  144. --
  145. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  146. --
  147. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  148. -- of this software and associated documentation files (the "Software"), to deal
  149. -- in the Software without restriction, including without limitation the rights
  150. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  151. -- copies of the Software, and to permit persons to whom the Software is
  152. -- furnished to do so, subject to the following conditions:
  153. --
  154. -- The above copyright notice and this permission notice shall be included in
  155. -- all copies or substantial portions of the Software.
  156. --
  157. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  158. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  159. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  160. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  161. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  162. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  163. -- THE SOFTWARE.