PageRenderTime 26ms CodeModel.GetById 17ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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