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