/src/lib/numeric/natural_8.e

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