PageRenderTime 13ms CodeModel.GetById 5ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/src/lib/numeric/float.e

http://github.com/tybor/Liberty
Specman e | 271 lines | 152 code | 43 blank | 76 comment | 2 complexity | 11e8217376b5f0f3931edafc6bdad603 MD5 | raw file
  1-- This file is part of a Liberty Eiffel library.
  2-- See the full copyright at the end.
  3--
  4deferred class FLOAT
  5   --
  6   -- This class defines the floating-point operations.
  7   --
  8
  9inherit
 10   NUMERIC
 11   COMPARABLE
 12
 13feature {ANY}
 14   infix "+" (another: like Current): like Current
 15      deferred
 16      end
 17
 18   infix "-" (another: like Current): like Current
 19      deferred
 20      end
 21
 22   infix "*" (another: like Current): like Current
 23      deferred
 24      end
 25
 26   infix "/" (another: like Current): like Current
 27     deferred
 28      end
 29
 30   infix "^" (another: INTEGER): like Current
 31         -- Raise Current to `e'-th power (see also `pow').
 32      deferred
 33      end
 34
 35   abs: like Current
 36      deferred
 37      end
 38
 39   is_not_a_number: BOOLEAN
 40         -- Also known as NaN in IEEE-754.
 41      deferred
 42      end
 43
 44   is_infinity: BOOLEAN
 45         -- Is either plus or minus infinity?
 46      deferred
 47      end
 48
 49   is_zero: BOOLEAN
 50         -- Is either -0.0 or +0.0 ?
 51      deferred
 52      ensure
 53         definition: Result = (Current = zero or else Current = -zero)
 54      end
 55
 56   infix "~=" (other: like Current): BOOLEAN
 57         -- Is `Current' near equal to `other'.
 58      deferred
 59      end
 60
 61   is_subnormal: BOOLEAN
 62         -- Is it too small to be represented in normalized format.
 63      deferred
 64      ensure
 65         Result = (Current = zero) or else Current = -zero
 66      end
 67
 68   is_normal: BOOLEAN
 69         -- The most general situation (see ensure).
 70      deferred
 71      ensure
 72         Result = not (is_subnormal or is_infinity or is_not_a_number)
 73      end
 74
 75   divisible (other: like Current): BOOLEAN
 76      deferred
 77      end
 78
 79feature {ANY} -- Conversions:
 80   frozen rounded: like Current
 81         -- Round to nearest integer away from zero.
 82      deferred
 83      end
 84
 85   frozen floor: like Current
 86         -- Largest integral value no greater than Current.
 87      deferred
 88      end
 89
 90   frozen ceiling: like Current
 91         -- Smallest integral value no smaller than Current.
 92      deferred
 93      end
 94
 95feature {ANY} -- Object Printing:
 96   to_string: STRING
 97         -- Convert `Current' into a new allocated STRING using 6 as the default number of digits for the
 98         -- fractional part.
 99         -- Example: `(1.5).to_string' will return "1.500000".
100         --
101         -- Note: see also `to_string_format', `to_string_scientific' as well as `append_in' to save memory.
102      deferred
103      end
104
105   to_string_format (f: INTEGER): STRING
106         -- Convert `Current' into a new allocated STRING using `f' digits for fractional part.
107         -- Example: `(1.5).to_string_format(2)' will return "1.50".
108         --
109         -- Note: see also `to_string_scientific', `to_string' as well as `append_in_format' to save memory.
110      require
111         f >= 0
112      deferred
113      end
114
115   to_string_scientific (f: INTEGER): STRING
116         -- Convert `Current' into a new allocated STRING, using the scientific notation with `f' digits for
117         -- the fractional part.
118         -- Example: `(155.5).to_string_scientific(4)' will return "1.5550e+02".
119         --
120         -- Note: see also `to_string', `to_string_format' as well as `append_in_scientific' to save memory.
121      deferred
122      end
123
124   append_in (buffer: STRING)
125         -- Append the equivalent of `to_string' at the end of `buffer'. Thus you can save
126         -- memory because no other STRING is allocated for the job.
127      require
128         buffer /= Void
129      deferred
130      end
131
132   append_in_format (str: STRING; f: INTEGER)
133         -- Append the equivalent of `to_string_format' at the end of `buffer'. Thus you can save
134         -- memory because no other STRING is allocated for the job.
135      require
136         str /= Void
137         f >= 0
138      deferred
139      end
140
141   append_in_scientific (str: STRING; f: INTEGER)
142         -- Append the equivalent of `to_string_scientific' at the end of `buffer'. Thus you can save
143         -- memory because no other STRING is allocated for the job.
144      require
145         str /= Void
146         f >= 0
147      deferred
148      end
149
150feature {ANY} -- Maths functions:
151   frozen sqrt: like Current
152         -- Square root of `Current'.
153      require
154         Current >= zero
155      deferred
156      end
157
158   frozen sin: like Current
159         -- Sine of `Current'.
160      deferred
161      end
162
163   frozen cos: like Current
164         -- Cosine of `Current'.
165      deferred
166      end
167
168   frozen tan: like Current
169         -- Tangent of `Current'.
170      deferred
171      end
172
173   frozen asin: like Current
174         -- Arc Sine of `Current'.
175      deferred
176      end
177
178   frozen acos: like Current
179         -- Arc Cosine of `Current'.
180      deferred
181      end
182
183   frozen atan: like Current
184         -- Arc Tangent of `Current'.
185      deferred
186      end
187
188   frozen atan2 (x: like Current): like Current
189         -- Arc Tangent of `Current' / `x'.
190      deferred
191      end
192
193   frozen sinh: like Current
194         -- Hyperbolic Sine of `Current'.
195      deferred
196      end
197
198   frozen cosh: like Current
199         -- Hyperbolic Cosine of `Current'.
200      deferred
201      end
202
203   frozen tanh: like Current
204         -- Hyperbolic Tangent of `Current'.
205      deferred
206      end
207
208   frozen exp: like Current
209         -- Exponential of `Current'.
210      deferred
211      end
212
213   frozen log: like Current
214         -- Natural Logarithm of `Current'.
215      deferred
216      end
217
218   frozen log10: like Current
219         -- Base-10 Logarithm of Current.
220      deferred
221      end
222
223   frozen pow (e: like Current): like Current
224         -- `Current' raised to the power of `e' (ANSI C `pow').
225      deferred
226      end
227
228feature {ANY} -- Hashing:
229   hash_code: INTEGER
230      deferred
231      end
232
233feature {ANY} -- Miscellaneous:
234   sign: INTEGER_8
235         -- Sign of `Current' (0 -1 or 1).
236      deferred
237      end
238
239   mantissa_bits: INTEGER_8
240         -- Give the number of bits, corresponding to the mantissa,
241         -- in the binary representation of the real number.
242      deferred
243      end
244
245   exponent_bits: INTEGER_8
246         -- Give the number of bits, corresponding to the exponent,
247         -- in the binary representation of the real number.
248      deferred
249      end
250
251end -- class FLOAT
252--
253-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
254--
255-- Permission is hereby granted, free of charge, to any person obtaining a copy
256-- of this software and associated documentation files (the "Software"), to deal
257-- in the Software without restriction, including without limitation the rights
258-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
259-- copies of the Software, and to permit persons to whom the Software is
260-- furnished to do so, subject to the following conditions:
261--
262-- The above copyright notice and this permission notice shall be included in
263-- all copies or substantial portions of the Software.
264--
265-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
266-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
267-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
268-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
269-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
270-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
271-- THE SOFTWARE.