/test/lib/numeric/real/test_maths.e

http://github.com/tybor/Liberty · Specman e · 134 lines · 108 code · 5 blank · 21 comment · 0 complexity · e7d80f98c88fe0c957f9e19aba1f9555 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. class TEST_MATHS
  5. insert
  6. EIFFELTEST_TOOLS
  7. PLATFORM
  8. create {}
  9. make
  10. feature {}
  11. make
  12. local
  13. i_8: INTEGER_8; i_16: INTEGER_16; i_32: INTEGER_32; i_64: INTEGER_64; r_32, real_32: REAL_32
  14. r_64, real_64: REAL_64
  15. do
  16. r_32 := Maximum_integer_8.to_real_32
  17. assert(r_32 = 1.27e+2)
  18. r_64 := Maximum_integer_8.to_real_64
  19. assert(r_64 = 1.27e+2)
  20. r_32 := Maximum_integer_16.to_real_32
  21. assert(r_32 = 3.2767e+04)
  22. r_64 := Maximum_integer_16.to_real_64
  23. assert(r_64 = 3.2767e+04)
  24. assert(not Maximum_integer_32.fit_real_32)
  25. real_32 := Maximum_integer_32.force_to_real_32
  26. real_64 := Maximum_integer_32.to_real_64
  27. assert(real_32 /= real_64)
  28. assert(Minimum_integer_32.fit_real_32)
  29. i_32 := -16777216
  30. assert(i_32.fit_real_32)
  31. real_32 := i_32.to_real_32
  32. assert(real_32.force_to_integer_32 = i_32)
  33. real_64 := i_32
  34. assert(real_32 = real_64)
  35. i_32 := -16777217
  36. assert(not i_32.fit_real_32)
  37. i_32 := -16777218
  38. assert(i_32.fit_real_32)
  39. real_32 := i_32.to_real_32
  40. assert(real_32.force_to_integer_32 = i_32)
  41. real_64 := i_32
  42. assert(real_32 = real_64)
  43. i_32 := 16777216
  44. assert(i_32.fit_real_32)
  45. real_32 := i_32.to_real_32
  46. real_64 := i_32
  47. assert(real_32 = real_64)
  48. i_32 := 16777217
  49. assert(not i_32.fit_real_32)
  50. i_32 := 16777218
  51. assert(i_32.fit_real_32)
  52. real_32 := i_32.to_real_32
  53. real_64 := i_32
  54. assert(real_32 = real_64)
  55. assert(not Maximum_integer_64.fit_real_64)
  56. assert(Minimum_integer_64.fit_real_64)
  57. i_64 := 9007199254740992
  58. assert(i_64.fit_real_64)
  59. real_64 := i_64.to_real_64
  60. assert(real_64.force_to_integer_64 = i_64)
  61. i_64 := 9007199254740995
  62. assert(not i_64.fit_real_64)
  63. i_64 := 9007199254740994
  64. assert(i_64.fit_real_64)
  65. real_64 := i_64.to_real_64
  66. assert(real_64.force_to_integer_64 = i_64)
  67. i_64 := -9007199254740992
  68. assert(i_64.fit_real_64)
  69. real_64 := i_64.force_to_real_64
  70. assert(real_64.force_to_integer_64 = i_64)
  71. i_64 := -9007199254740993
  72. assert(not i_64.fit_real_64)
  73. i_64 := -9007199254740994
  74. assert(i_64.fit_real_64)
  75. real_64 := i_64.force_to_real_64
  76. assert(real_64.force_to_integer_64 = i_64)
  77. i_8 := 1
  78. r_64 := i_8.log
  79. assert(r_64 = 0.0)
  80. i_16 := 1
  81. r_64 := i_16.log
  82. assert(r_64 = 0.0)
  83. i_32 := 1
  84. r_64 := i_32.log
  85. assert(r_64 = 0.0)
  86. i_64 := 1
  87. r_64 := i_64.log
  88. assert(r_64 = 0.0)
  89. i_8 := 1
  90. r_64 := i_8.log10
  91. assert(r_64 = 0.0)
  92. i_16 := 1
  93. r_64 := i_16.log10
  94. assert(r_64 = 0.0)
  95. i_32 := 1
  96. r_64 := i_32.log10
  97. assert(r_64 = 0.0)
  98. i_64 := 1
  99. r_64 := i_64.log10
  100. assert(r_64 = 0.0)
  101. number := Maximum_integer_8.to_number
  102. assert(number @= Maximum_integer_8)
  103. number := Maximum_integer_16.to_number
  104. assert(number @= Maximum_integer_16)
  105. number := Maximum_integer_32.to_number
  106. assert(number @= Maximum_integer_32)
  107. number := Maximum_integer_64.to_number
  108. assert(number @= Maximum_integer_64)
  109. end
  110. number: NUMBER
  111. end -- class TEST_MATHS
  112. --
  113. -- ------------------------------------------------------------------------------------------------------------------------------
  114. -- Copyright notice below. Please read.
  115. --
  116. -- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
  117. -- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
  118. -- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
  119. -- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
  120. -- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
  121. -- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  122. --
  123. -- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE
  124. -- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
  125. --
  126. -- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
  127. --
  128. -- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
  129. -- ------------------------------------------------------------------------------------------------------------------------------