pow_basic.phpt 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. --TEST--
  2. Test pow() - basic function test pow()
  3. --INI--
  4. precision=14
  5. --SKIPIF--
  6. <?php
  7. if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
  8. ?>
  9. --FILE--
  10. <?php
  11. $bases = array(23,
  12. -23,
  13. 23.1,
  14. -23.1,
  15. 2.345e1,
  16. -2.345e1,
  17. 0x17,
  18. 027,
  19. "23",
  20. "23.45",
  21. "2.345e1",
  22. PHP_INT_MAX,
  23. -PHP_INT_MAX - 1);
  24. $exponents = array(0,
  25. 1,
  26. -1,
  27. 2,
  28. -2,
  29. 3,
  30. -3,
  31. 2.5,
  32. -2.5,
  33. 500,
  34. -500,
  35. 2147483647,
  36. -2147483648);
  37. foreach($bases as $base) {
  38. echo "\n\nBase = $base";
  39. foreach($exponents as $exponent) {
  40. echo "\n..... Exponent = $exponent Result = ";
  41. $res = pow($base, $exponent);
  42. echo $res;
  43. }
  44. echo "\n\n";
  45. }
  46. ?>
  47. ===Done===
  48. --EXPECT--
  49. Base = 23
  50. ..... Exponent = 0 Result = 1
  51. ..... Exponent = 1 Result = 23
  52. ..... Exponent = -1 Result = 0.043478260869565
  53. ..... Exponent = 2 Result = 529
  54. ..... Exponent = -2 Result = 0.001890359168242
  55. ..... Exponent = 3 Result = 12167
  56. ..... Exponent = -3 Result = 8.2189529053999E-5
  57. ..... Exponent = 2.5 Result = 2536.9948758324
  58. ..... Exponent = -2.5 Result = 0.00039416713432339
  59. ..... Exponent = 500 Result = INF
  60. ..... Exponent = -500 Result = 0
  61. ..... Exponent = 2147483647 Result = INF
  62. ..... Exponent = -2147483648 Result = 0
  63. Base = -23
  64. ..... Exponent = 0 Result = 1
  65. ..... Exponent = 1 Result = -23
  66. ..... Exponent = -1 Result = -0.043478260869565
  67. ..... Exponent = 2 Result = 529
  68. ..... Exponent = -2 Result = 0.001890359168242
  69. ..... Exponent = 3 Result = -12167
  70. ..... Exponent = -3 Result = -8.2189529053999E-5
  71. ..... Exponent = 2.5 Result = NAN
  72. ..... Exponent = -2.5 Result = NAN
  73. ..... Exponent = 500 Result = INF
  74. ..... Exponent = -500 Result = 0
  75. ..... Exponent = 2147483647 Result = -INF
  76. ..... Exponent = -2147483648 Result = 0
  77. Base = 23.1
  78. ..... Exponent = 0 Result = 1
  79. ..... Exponent = 1 Result = 23.1
  80. ..... Exponent = -1 Result = 0.043290043290043
  81. ..... Exponent = 2 Result = 533.61
  82. ..... Exponent = -2 Result = 0.0018740278480538
  83. ..... Exponent = 3 Result = 12326.391
  84. ..... Exponent = -3 Result = 8.1126746668997E-5
  85. ..... Exponent = 2.5 Result = 2564.6608940579
  86. ..... Exponent = -2.5 Result = 0.00038991509650141
  87. ..... Exponent = 500 Result = INF
  88. ..... Exponent = -500 Result = 0
  89. ..... Exponent = 2147483647 Result = INF
  90. ..... Exponent = -2147483648 Result = 0
  91. Base = -23.1
  92. ..... Exponent = 0 Result = 1
  93. ..... Exponent = 1 Result = -23.1
  94. ..... Exponent = -1 Result = -0.043290043290043
  95. ..... Exponent = 2 Result = 533.61
  96. ..... Exponent = -2 Result = 0.0018740278480538
  97. ..... Exponent = 3 Result = -12326.391
  98. ..... Exponent = -3 Result = -8.1126746668997E-5
  99. ..... Exponent = 2.5 Result = NAN
  100. ..... Exponent = -2.5 Result = NAN
  101. ..... Exponent = 500 Result = INF
  102. ..... Exponent = -500 Result = 0
  103. ..... Exponent = 2147483647 Result = -INF
  104. ..... Exponent = -2147483648 Result = 0
  105. Base = 23.45
  106. ..... Exponent = 0 Result = 1
  107. ..... Exponent = 1 Result = 23.45
  108. ..... Exponent = -1 Result = 0.042643923240938
  109. ..... Exponent = 2 Result = 549.9025
  110. ..... Exponent = -2 Result = 0.001818504189379
  111. ..... Exponent = 3 Result = 12895.213625
  112. ..... Exponent = -3 Result = 7.7548153065204E-5
  113. ..... Exponent = 2.5 Result = 2662.9138571162
  114. ..... Exponent = -2.5 Result = 0.00037552848257846
  115. ..... Exponent = 500 Result = INF
  116. ..... Exponent = -500 Result = 0
  117. ..... Exponent = 2147483647 Result = INF
  118. ..... Exponent = -2147483648 Result = 0
  119. Base = -23.45
  120. ..... Exponent = 0 Result = 1
  121. ..... Exponent = 1 Result = -23.45
  122. ..... Exponent = -1 Result = -0.042643923240938
  123. ..... Exponent = 2 Result = 549.9025
  124. ..... Exponent = -2 Result = 0.001818504189379
  125. ..... Exponent = 3 Result = -12895.213625
  126. ..... Exponent = -3 Result = -7.7548153065204E-5
  127. ..... Exponent = 2.5 Result = NAN
  128. ..... Exponent = -2.5 Result = NAN
  129. ..... Exponent = 500 Result = INF
  130. ..... Exponent = -500 Result = 0
  131. ..... Exponent = 2147483647 Result = -INF
  132. ..... Exponent = -2147483648 Result = 0
  133. Base = 23
  134. ..... Exponent = 0 Result = 1
  135. ..... Exponent = 1 Result = 23
  136. ..... Exponent = -1 Result = 0.043478260869565
  137. ..... Exponent = 2 Result = 529
  138. ..... Exponent = -2 Result = 0.001890359168242
  139. ..... Exponent = 3 Result = 12167
  140. ..... Exponent = -3 Result = 8.2189529053999E-5
  141. ..... Exponent = 2.5 Result = 2536.9948758324
  142. ..... Exponent = -2.5 Result = 0.00039416713432339
  143. ..... Exponent = 500 Result = INF
  144. ..... Exponent = -500 Result = 0
  145. ..... Exponent = 2147483647 Result = INF
  146. ..... Exponent = -2147483648 Result = 0
  147. Base = 23
  148. ..... Exponent = 0 Result = 1
  149. ..... Exponent = 1 Result = 23
  150. ..... Exponent = -1 Result = 0.043478260869565
  151. ..... Exponent = 2 Result = 529
  152. ..... Exponent = -2 Result = 0.001890359168242
  153. ..... Exponent = 3 Result = 12167
  154. ..... Exponent = -3 Result = 8.2189529053999E-5
  155. ..... Exponent = 2.5 Result = 2536.9948758324
  156. ..... Exponent = -2.5 Result = 0.00039416713432339
  157. ..... Exponent = 500 Result = INF
  158. ..... Exponent = -500 Result = 0
  159. ..... Exponent = 2147483647 Result = INF
  160. ..... Exponent = -2147483648 Result = 0
  161. Base = 23
  162. ..... Exponent = 0 Result = 1
  163. ..... Exponent = 1 Result = 23
  164. ..... Exponent = -1 Result = 0.043478260869565
  165. ..... Exponent = 2 Result = 529
  166. ..... Exponent = -2 Result = 0.001890359168242
  167. ..... Exponent = 3 Result = 12167
  168. ..... Exponent = -3 Result = 8.2189529053999E-5
  169. ..... Exponent = 2.5 Result = 2536.9948758324
  170. ..... Exponent = -2.5 Result = 0.00039416713432339
  171. ..... Exponent = 500 Result = INF
  172. ..... Exponent = -500 Result = 0
  173. ..... Exponent = 2147483647 Result = INF
  174. ..... Exponent = -2147483648 Result = 0
  175. Base = 23.45
  176. ..... Exponent = 0 Result = 1
  177. ..... Exponent = 1 Result = 23.45
  178. ..... Exponent = -1 Result = 0.042643923240938
  179. ..... Exponent = 2 Result = 549.9025
  180. ..... Exponent = -2 Result = 0.001818504189379
  181. ..... Exponent = 3 Result = 12895.213625
  182. ..... Exponent = -3 Result = 7.7548153065204E-5
  183. ..... Exponent = 2.5 Result = 2662.9138571162
  184. ..... Exponent = -2.5 Result = 0.00037552848257846
  185. ..... Exponent = 500 Result = INF
  186. ..... Exponent = -500 Result = 0
  187. ..... Exponent = 2147483647 Result = INF
  188. ..... Exponent = -2147483648 Result = 0
  189. Base = 2.345e1
  190. ..... Exponent = 0 Result = 1
  191. ..... Exponent = 1 Result = 23.45
  192. ..... Exponent = -1 Result = 0.042643923240938
  193. ..... Exponent = 2 Result = 549.9025
  194. ..... Exponent = -2 Result = 0.001818504189379
  195. ..... Exponent = 3 Result = 12895.213625
  196. ..... Exponent = -3 Result = 7.7548153065204E-5
  197. ..... Exponent = 2.5 Result = 2662.9138571162
  198. ..... Exponent = -2.5 Result = 0.00037552848257846
  199. ..... Exponent = 500 Result = INF
  200. ..... Exponent = -500 Result = 0
  201. ..... Exponent = 2147483647 Result = INF
  202. ..... Exponent = -2147483648 Result = 0
  203. Base = 2147483647
  204. ..... Exponent = 0 Result = 1
  205. ..... Exponent = 1 Result = 2147483647
  206. ..... Exponent = -1 Result = 4.6566128752458E-10
  207. ..... Exponent = 2 Result = 4.6116860141324E+18
  208. ..... Exponent = -2 Result = 2.1684043469905E-19
  209. ..... Exponent = 3 Result = 9.903520300448E+27
  210. ..... Exponent = -3 Result = 1.0097419600935E-28
  211. ..... Exponent = 2.5 Result = 2.1370991100146E+23
  212. ..... Exponent = -2.5 Result = 4.6792401686657E-24
  213. ..... Exponent = 500 Result = INF
  214. ..... Exponent = -500 Result = 0
  215. ..... Exponent = 2147483647 Result = INF
  216. ..... Exponent = -2147483648 Result = 0
  217. Base = -2147483648
  218. ..... Exponent = 0 Result = 1
  219. ..... Exponent = 1 Result = -2147483648
  220. ..... Exponent = -1 Result = -4.6566128730774E-10
  221. ..... Exponent = 2 Result = 4.6116860184274E+18
  222. ..... Exponent = -2 Result = 2.168404344971E-19
  223. ..... Exponent = 3 Result = -9.903520314283E+27
  224. ..... Exponent = -3 Result = -1.0097419586829E-28
  225. ..... Exponent = 2.5 Result = NAN
  226. ..... Exponent = -2.5 Result = NAN
  227. ..... Exponent = 500 Result = INF
  228. ..... Exponent = -500 Result = 0
  229. ..... Exponent = 2147483647 Result = -INF
  230. ..... Exponent = -2147483648 Result = 0
  231. ===Done===