/test/language/expanded/aux_ac_complex.e

http://github.com/tybor/Liberty · Specman e · 166 lines · 117 code · 25 blank · 24 comment · 2 complexity · f3ea8fbc6c284c129a545e8a537eb126 MD5 · raw file

  1. -- This file is part of SmartEiffel The GNU Eiffel Compiler Tools and Libraries.
  2. -- See the Copyright notice at the end of this file.
  3. --
  4. expanded class AUX_AC_COMPLEX
  5. insert
  6. NUMERIC
  7. redefine out
  8. end
  9. feature {ANY}
  10. is_equal (other: like Current): BOOLEAN
  11. do
  12. Result := standard_is_equal(other)
  13. end
  14. is_near_equal (other: like Current): BOOLEAN
  15. do
  16. Result := (re - other.re).abs * 2.0 ^ 45 < re.abs and (im - other.im).abs * 2.0 ^ 45 < im.abs
  17. end
  18. re: REAL
  19. im: REAL
  20. make (r, i: REAL): like Current
  21. do
  22. Result.set_item(r, i)
  23. end
  24. set_item (r, i: REAL)
  25. do
  26. re := r
  27. im := i
  28. end
  29. infix "+" (other: like Current): like Current
  30. do
  31. Result.set_item(re + other.re, im + other.im)
  32. end
  33. infix "-" (other: like Current): like Current
  34. do
  35. Result.set_item(re - other.re, im - other.im)
  36. end
  37. infix "*" (other: like Current): like Current
  38. do
  39. Result.set_item(re * other.re - im * other.im, re * other.im + im * other.re)
  40. end
  41. infix "/" (other: like Current): like Current
  42. -- The ratio of self and `other'.
  43. -- From Numerical Recipes in C, 2nd ed. p. 949.
  44. local
  45. r, den: REAL
  46. do
  47. if other.re.abs >= other.im.abs then
  48. r := other.im / other.re
  49. den := other.re + r * other.im
  50. Result.set_item((re + r * im) / den, (im - r * re) / den)
  51. else
  52. r := other.re / other.im
  53. den := other.im + r * other.re
  54. Result.set_item((re * r + im) / den, (im * r - re) / den)
  55. end
  56. end
  57. prefix "-": like Current
  58. do
  59. Result.set_item(-re, -im)
  60. end
  61. prefix "+": like Current
  62. do
  63. Result.set_item(re, im)
  64. end
  65. valid_divisor (other: like Current): BOOLEAN
  66. do
  67. Result := other /= zero
  68. end
  69. sign: INTEGER_8
  70. do
  71. check
  72. False
  73. end
  74. end
  75. divisible (other: like Current): BOOLEAN
  76. do
  77. Result := re /= 0 or else im /= 0
  78. end
  79. one: like Current
  80. do
  81. Result.set_item(re.one, im.zero)
  82. end
  83. zero: like Current
  84. do
  85. Result.set_item(re.zero, im.zero)
  86. end
  87. plus_scalar (scalar: REAL): like Current
  88. do
  89. Result.set_item(re + scalar, im)
  90. end
  91. times_scalar (scalar: REAL): like Current
  92. do
  93. Result.set_item(re * scalar, im * scalar)
  94. end
  95. exp: like Current
  96. -- The complex exponential `e^self'.
  97. local
  98. rp: REAL
  99. do
  100. rp := re.exp
  101. Result.set_item(rp * im.cos, rp * im.sin)
  102. end
  103. out: STRING
  104. do
  105. create Result.make(24)
  106. Result.append("(")
  107. Result.append(re.out)
  108. Result.append(", ")
  109. Result.append(im.out)
  110. Result.append(")")
  111. ensure
  112. not Result.is_empty
  113. end
  114. set_item_numeric (other: like Current)
  115. do
  116. set_item(other.re, other.im)
  117. end
  118. feature {ANY}
  119. hash_code: INTEGER
  120. do
  121. Result := re.hash_code + im.hash_code
  122. end
  123. end -- class AUX_AC_COMPLEX
  124. --
  125. -- ------------------------------------------------------------------------------------------------------------------------------
  126. -- Copyright notice below. Please read.
  127. --
  128. -- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
  129. -- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
  130. -- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
  131. -- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
  132. -- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
  133. -- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  134. --
  135. -- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE
  136. -- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
  137. --
  138. -- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
  139. --
  140. -- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
  141. -- ------------------------------------------------------------------------------------------------------------------------------