/src/lib/numeric/integer_8.e

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