PageRenderTime 21ms CodeModel.GetById 17ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 1ms

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