PageRenderTime 15ms CodeModel.GetById 6ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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