PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/runtime/ext/std/ext_std_math.php

http://github.com/facebook/hiphop-php
PHP | 624 lines | 103 code | 49 blank | 472 comment | 0 complexity | 6e14742231b2fdcb594b4fcc320f8033 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?hh // partial
  2. /**
  3. * @return float - The value of pi as float.
  4. *
  5. */
  6. <<__IsFoldable, __Rx>>
  7. function pi(): float {
  8. return M_PI;
  9. }
  10. /**
  11. * If the first and only parameter is an array, min() returns the lowest value
  12. * in that array. If at least two parameters are provided, min() returns the
  13. * smallest of these values. PHP will evaluate a non-numeric string as 0 if
  14. * compared to integer, but still return the string if it's seen as the
  15. * numerically lowest value. If multiple arguments evaluate to 0, min() will
  16. * return the lowest alphanumerical string value if any strings are given,
  17. * else a numeric 0 is returned.
  18. *
  19. * @param mixed $value - An array containing the values.
  20. * @param mixed $second - A second value to compare.
  21. *
  22. * @return mixed - min() returns the numerically lowest of the parameter
  23. * values.
  24. *
  25. */
  26. <<__IsFoldable, __Native, __Rx>>
  27. function min(mixed $value1, ...$argv): mixed;
  28. /**
  29. * If the first and only parameter is an array, max() returns the highest
  30. * value in that array. If at least two parameters are provided, max() returns
  31. * the biggest of these values. PHP will evaluate a non-numeric string as 0
  32. * if compared to integer, but still return the string if it's seen as the
  33. * numerically highest value. If multiple arguments evaluate to 0, max() will
  34. * return a numeric 0 if given, else the alphabetical highest string value
  35. * will be returned.
  36. *
  37. * @param mixed $value - An array containing the values.
  38. * @param mixed $second - A second value to compare.
  39. *
  40. * @return mixed - max() returns the numerically highest of the parameter
  41. * values. If multiple values can be considered of the same size, the one that
  42. * is listed first will be returned. When max() is given multiple arrays, the
  43. * longest array is returned. If all the arrays have the same length, max()
  44. * will use lexicographic ordering to find the return value. When given a
  45. * string it will be cast as an integer when comparing.
  46. *
  47. */
  48. <<__IsFoldable, __Native, __Rx>>
  49. function max(mixed $value1, ...$argv): mixed;
  50. /**
  51. * Returns the absolute value of number.
  52. *
  53. * @param mixed $number - The numeric value to process
  54. *
  55. * @return mixed - The absolute value of number. If the argument number is of
  56. * type float, the return type is also float, otherwise it is integer (as
  57. * float usually has a bigger value range than integer).
  58. *
  59. */
  60. <<__IsFoldable, __Native, __Rx>>
  61. function abs(mixed $number): mixed;
  62. /**
  63. * Checks whether val is a legal finite on this platform.
  64. *
  65. * @param float $val - The value to check
  66. *
  67. * @return bool - TRUE if val is a legal finite number within the allowed
  68. * range for a PHP float on this platform, else FALSE.
  69. *
  70. */
  71. <<__IsFoldable, __Native, __Rx>>
  72. function is_finite(float $val): bool;
  73. /**
  74. * Returns TRUE if val is infinite (positive or negative), like the result of
  75. * log(0) or any value too big to fit into a float on this platform.
  76. *
  77. * @param float $val - The value to check
  78. *
  79. * @return bool - TRUE if val is infinite, else FALSE.
  80. *
  81. */
  82. <<__IsFoldable, __Native, __Rx>>
  83. function is_infinite(float $val): bool;
  84. /**
  85. * Checks whether val is 'not a number', like the result of acos(1.01).
  86. *
  87. * @param float $val - The value to check
  88. *
  89. * @return bool - Returns TRUE if val is 'not a number', else FALSE.
  90. *
  91. */
  92. <<__IsFoldable, __Native, __Rx>>
  93. function is_nan(float $val): bool;
  94. /**
  95. * @param mixed $number - The value to round
  96. *
  97. * @return mixed - value rounded up to the next highest integer. The return
  98. * value of ceil() is still of type float as the value range of float is
  99. * usually bigger than that of integer.
  100. *
  101. */
  102. <<__IsFoldable, __Native, __Rx>>
  103. function ceil(mixed $number): mixed;
  104. /**
  105. * @param mixed $number - The numeric value to round
  106. *
  107. * @return mixed - value rounded to the next lowest integer. The return value
  108. * of floor() is still of type float because the value range of float is
  109. * usually bigger than that of integer.
  110. *
  111. */
  112. <<__IsFoldable, __Native, __Rx>>
  113. function floor(mixed $number): mixed;
  114. /**
  115. * Returns the rounded value of val to specified precision (number of digits
  116. * after the decimal point). precision can also be negative or zero (default).
  117. * PHP doesn't handle strings like "12,300.2" correctly by default. See
  118. * converting from strings.
  119. *
  120. * @param mixed $val - The value to round
  121. * @param int $precision - The optional number of decimal digits to round to.
  122. * @param int $mode - One of the PHP_ROUND_HALF_* constants to determine how
  123. * rounding should occur.
  124. *
  125. * @return mixed - The rounded value
  126. *
  127. */
  128. <<__IsFoldable, __Native, __Rx>>
  129. function round(mixed $val,
  130. int $precision = 0,
  131. int $mode = PHP_ROUND_HALF_UP): mixed;
  132. /**
  133. * This function converts number from degrees to the radian equivalent.
  134. *
  135. * @param float $number - Angular value in degrees
  136. *
  137. * @return float - The radian equivalent of number
  138. *
  139. */
  140. <<__IsFoldable, __Native, __Rx>>
  141. function deg2rad(float $number): float;
  142. /**
  143. * This function converts number from radian to degrees.
  144. *
  145. * @param float $number - A radian value
  146. *
  147. * @return float - The equivalent of number in degrees
  148. *
  149. */
  150. <<__IsFoldable, __Native, __Rx>>
  151. function rad2deg(float $number): float;
  152. /**
  153. * Returns a string containing a binary representation of the given number
  154. * argument.
  155. *
  156. * @param int $number
  157. *
  158. * @return string - Binary string representation of number
  159. *
  160. */
  161. <<__IsFoldable, __Native, __Rx>>
  162. function decbin(mixed $number): string;
  163. /**
  164. * Returns a string containing a hexadecimal representation of the given
  165. * number argument. The largest number that can be converted is 4294967295 in
  166. * decimal resulting to "ffffffff".
  167. *
  168. * @param int $number - Decimal value to convert
  169. *
  170. * @return string - Hexadecimal string representation of number
  171. *
  172. */
  173. <<__IsFoldable, __Native, __Rx>>
  174. function dechex(mixed $number): string;
  175. /**
  176. * Returns a string containing an octal representation of the given number
  177. * argument. The largest number that can be converted is 4294967295 in decimal
  178. * resulting to "37777777777".
  179. *
  180. * @param int $number - Decimal value to convert
  181. *
  182. * @return string - Octal string representation of number
  183. *
  184. */
  185. <<__IsFoldable, __Native, __Rx>>
  186. function decoct(mixed $number): string;
  187. /**
  188. * Returns the decimal equivalent of the binary number represented by the
  189. * binary_string argument. bindec() converts a binary number to an integer
  190. * or, if needed for size reasons, float. bindec() interprets all
  191. * binary_string values as unsigned integers. This is because bindec() sees
  192. * the most significant bit as another order of magnitude rather than as the
  193. * sign bit. Warning The parameter must be a string. Using other data types
  194. * will produce unexpected results.
  195. *
  196. * @param string $binary_string - The binary string to convert
  197. *
  198. * @return mixed - The decimal value of binary_string
  199. *
  200. */
  201. <<__IsFoldable, __Native, __Rx>>
  202. function bindec(mixed $binary_string): mixed;
  203. /**
  204. * Returns the decimal equivalent of the hexadecimal number represented by the
  205. * hex_string argument. hexdec() converts a hexadecimal string to a decimal
  206. * number. hexdec() will ignore any non-hexadecimal characters it encounters.
  207. *
  208. * @param string $hex_string - The hexadecimal string to convert
  209. *
  210. * @return mixed - The decimal representation of hex_string
  211. *
  212. */
  213. <<__IsFoldable, __Native, __Rx>>
  214. function hexdec(mixed $hex_string): mixed;
  215. /**
  216. * Returns the decimal equivalent of the octal number represented by the
  217. * octal_string argument.
  218. *
  219. * @param string $octal_string - The octal string to convert
  220. *
  221. * @return mixed - The decimal representation of octal_string
  222. *
  223. */
  224. <<__IsFoldable, __Native, __Rx>>
  225. function octdec(mixed $octal_string): mixed;
  226. /**
  227. * Returns a string containing number represented in base tobase. The base in
  228. * which number is given is specified in frombase. Both frombase and tobase
  229. * have to be between 2 and 36, inclusive. Digits in numbers with a base
  230. * higher than 10 will be represented with the letters a-z, with a meaning 10,
  231. * b meaning 11 and z meaning 35. Warning base_convert() may lose precision on
  232. * large numbers due to properties related to the internal "double" or "float"
  233. * type used. Please see the Floating point numbers section in the manual for
  234. * more specific information and limitations.
  235. *
  236. * @param string $number - The number to convert
  237. * @param int $frombase - The base number is in
  238. * @param int $tobase - The base to convert number to
  239. *
  240. * @return mixed - number converted to base tobase
  241. *
  242. */
  243. <<__IsFoldable, __Native, __Rx>>
  244. function base_convert(mixed $number, int $frombase, int $tobase): mixed;
  245. /**
  246. * Returns base raised to the power of exp. Warning In PHP 4.0.6 and earlier
  247. * pow() always returned a float, and did not issue warnings.
  248. *
  249. * @param mixed $base - The base to use
  250. * @param mixed $exp - The exponent
  251. *
  252. * @return mixed - base raised to the power of exp. If the result can be
  253. * represented as integer it will be returned as type integer, else it will be
  254. * returned as type float. If the power cannot be computed FALSE will be
  255. * returned instead.
  256. *
  257. */
  258. <<__IsFoldable, __Native, __Rx>>
  259. function pow(mixed $base, mixed $exp): mixed;
  260. /**
  261. * Returns e raised to the power of arg. 'e' is the base of the natural
  262. * system of logarithms, or approximately 2.718282.
  263. *
  264. * @param float $arg - The argument to process
  265. *
  266. * @return float - 'e' raised to the power of arg
  267. *
  268. */
  269. <<__IsFoldable, __Native, __Rx>>
  270. function exp(float $arg): float;
  271. /**
  272. * expm1() returns the equivalent to 'exp(arg) - 1' computed in a way that is
  273. * accurate even if the value of arg is near zero, a case where 'exp (arg) -
  274. * 1' would be inaccurate due to subtraction of two numbers that are nearly
  275. * equal.
  276. *
  277. * @param float $arg - The argument to process
  278. *
  279. * @return float - 'e' to the power of arg minus one
  280. *
  281. */
  282. <<__IsFoldable, __Native, __Rx>>
  283. function expm1(float $arg): float;
  284. /**
  285. * Returns the base-10 logarithm of arg.
  286. *
  287. * @param float $arg - The argument to process
  288. *
  289. * @return float - The base-10 logarithm of arg
  290. *
  291. */
  292. <<__IsFoldable, __Native, __Rx>>
  293. function log10(float $arg): float;
  294. /**
  295. * log1p() returns log(1 + number) computed in a way that is accurate even
  296. * when the value of number is close to zero. log() might only return log(1)
  297. * in this case due to lack of precision.
  298. *
  299. * @param float $number - The argument to process
  300. *
  301. * @return float - log(1 + number)
  302. *
  303. */
  304. <<__IsFoldable, __Native, __Rx>>
  305. function log1p(float $number): float;
  306. /**
  307. * If the optional base parameter is specified, log() returns logbase arg,
  308. * otherwise log() returns the natural logarithm of arg.
  309. *
  310. * @param float $arg - The value to calculate the logarithm for
  311. * @param float $base - The optional logarithmic base to use (defaults to 'e'
  312. * and so to the natural logarithm).
  313. *
  314. * @return float - The logarithm of arg to base, if given, or the natural
  315. * logarithm.
  316. *
  317. */
  318. <<__IsFoldable, __Native, __Rx>>
  319. function log(float $arg, float $base = 0.0): float;
  320. /**
  321. * cos() returns the cosine of the arg parameter. The arg parameter is in
  322. * radians.
  323. *
  324. * @param float $arg - An angle in radians
  325. *
  326. * @return float - The cosine of arg
  327. *
  328. */
  329. <<__IsFoldable, __Native, __Rx>>
  330. function cos(float $arg): float;
  331. /**
  332. * Returns the hyperbolic cosine of arg, defined as (exp(arg) + exp(-arg))/2.
  333. *
  334. * @param float $arg - The argument to process
  335. *
  336. * @return float - The hyperbolic cosine of arg
  337. *
  338. */
  339. <<__IsFoldable, __Native, __Rx>>
  340. function cosh(float $arg): float;
  341. /**
  342. * sin() returns the sine of the arg parameter. The arg parameter is in
  343. * radians.
  344. *
  345. * @param float $arg - A value in radians
  346. *
  347. * @return float - The sine of arg
  348. *
  349. */
  350. <<__IsFoldable, __Native, __Rx>>
  351. function sin(float $arg): float;
  352. /**
  353. * Returns the hyperbolic sine of arg, defined as (exp(arg) - exp(-arg))/2.
  354. *
  355. * @param float $arg - The argument to process
  356. *
  357. * @return float - The hyperbolic sine of arg
  358. *
  359. */
  360. <<__IsFoldable, __Native, __Rx>>
  361. function sinh(float $arg): float;
  362. /**
  363. * tan() returns the tangent of the arg parameter. The arg parameter is in
  364. * radians.
  365. *
  366. * @param float $arg - The argument to process in radians
  367. *
  368. * @return float - The tangent of arg
  369. *
  370. */
  371. <<__IsFoldable, __Native, __Rx>>
  372. function tan(float $arg): float;
  373. /**
  374. * Returns the hyperbolic tangent of arg, defined as sinh(arg)/cosh(arg).
  375. *
  376. * @param float $arg - The argument to process
  377. *
  378. * @return float - The hyperbolic tangent of arg
  379. *
  380. */
  381. <<__IsFoldable, __Native, __Rx>>
  382. function tanh(float $arg): float;
  383. /**
  384. * Returns the arc cosine of arg in radians. acos() is the complementary
  385. * function of cos(), which means that a==cos(acos(a)) for every value of a
  386. * that is within acos()' range.
  387. *
  388. * @param float $arg - The argument to process
  389. *
  390. * @return float - The arc cosine of arg in radians.
  391. *
  392. */
  393. <<__IsFoldable, __Native, __Rx>>
  394. function acos(float $arg): float;
  395. /**
  396. * Returns the inverse hyperbolic cosine of arg, i.e. the value whose
  397. * hyperbolic cosine is arg.
  398. *
  399. * @param float $arg - The value to process
  400. *
  401. * @return float - The inverse hyperbolic cosine of arg
  402. *
  403. */
  404. <<__IsFoldable, __Native, __Rx>>
  405. function acosh(float $arg): float;
  406. /**
  407. * Returns the arc sine of arg in radians. asin() is the complementary
  408. * function of sin(), which means that a==sin(asin(a)) for every value of a
  409. * that is within asin()'s range.
  410. *
  411. * @param float $arg - The argument to process
  412. *
  413. * @return float - The arc sine of arg in radians
  414. *
  415. */
  416. <<__IsFoldable, __Native, __Rx>>
  417. function asin(float $arg): float;
  418. /**
  419. * Returns the inverse hyperbolic sine of arg, i.e. the value whose hyperbolic
  420. * sine is arg.
  421. *
  422. * @param float $arg - The argument to process
  423. *
  424. * @return float - The inverse hyperbolic sine of arg
  425. *
  426. */
  427. <<__IsFoldable, __Native, __Rx>>
  428. function asinh(float $arg): float;
  429. /**
  430. * Returns the arc tangent of arg in radians. atan() is the complementary
  431. * function of tan(), which means that a==tan(atan(a)) for every value of a
  432. * that is within atan()'s range.
  433. *
  434. * @param float $arg - The argument to process
  435. *
  436. * @return float - The arc tangent of arg in radians.
  437. *
  438. */
  439. <<__IsFoldable, __Native, __Rx>>
  440. function atan(float $arg): float;
  441. /**
  442. * Returns the inverse hyperbolic tangent of arg, i.e. the value whose
  443. * hyperbolic tangent is arg.
  444. *
  445. * @param float $arg - The argument to process
  446. *
  447. * @return float - Inverse hyperbolic tangent of arg
  448. *
  449. */
  450. <<__IsFoldable, __Native, __Rx>>
  451. function atanh(float $arg): float;
  452. /**
  453. * @param float $y - Dividend parameter
  454. * @param float $x - Divisor parameter
  455. *
  456. * @return float - The arc tangent of y/x in radians.
  457. *
  458. */
  459. <<__IsFoldable, __Native, __Rx>>
  460. function atan2(float $y, float $x): float;
  461. /**
  462. * hypot() returns the length of the hypotenuse of a right-angle triangle with
  463. * sides of length x and y, or the distance of the point (x, y) from the
  464. * origin. This is equivalent to sqrt(x*x + y*y).
  465. *
  466. * @param float $x - Length of first side
  467. * @param float $y - Length of second side
  468. *
  469. * @return float - Calculated length of the hypotenuse
  470. *
  471. */
  472. <<__IsFoldable, __Native, __Rx>>
  473. function hypot(float $x, float $y): float;
  474. /**
  475. * Returns the floating point remainder of dividing the dividend (x) by the
  476. * divisor (y). The reminder (r) is defined as: x = i * y + r, for some
  477. * integer i. If y is non-zero, r has the same sign as x and a magnitude less
  478. * than the magnitude of y.
  479. *
  480. * @param float $x - The dividend
  481. * @param float $y - The divisor
  482. *
  483. * @return float - The floating point remainder of x/y
  484. *
  485. */
  486. <<__IsFoldable, __Native, __Rx>>
  487. function fmod(float $x, float $y): float;
  488. /**
  489. * Returns the square root of arg.
  490. *
  491. * @param float $arg - The argument to process
  492. *
  493. * @return float - The square root of arg or the special value NAN for
  494. * negative numbers.
  495. *
  496. */
  497. <<__IsFoldable, __Native, __Rx>>
  498. function sqrt(float $arg): float;
  499. /**
  500. * @return int - The largest possible random value returned by rand()
  501. *
  502. */
  503. <<__IsFoldable, __Native>>
  504. function getrandmax(): int;
  505. /**
  506. * Seeds the random number generator with seed or with a random value if no
  507. * seed is given. As of PHP 4.2.0, there is no need to seed the random number
  508. * generator with srand() or mt_srand() as this is now done automatically.
  509. *
  510. * @param mixed $seed - Optional seed value
  511. *
  512. */
  513. <<__Native, __NonRx('Randomness')>>
  514. function srand(mixed $seed = null): void;
  515. /**
  516. * @param int $min - The lowest value to return (default: 0)
  517. * @param int $max - The highest value to return (default: getrandmax())
  518. *
  519. * @return int - A pseudo random value between min (or 0) and max (or
  520. * getrandmax(), inclusive).
  521. *
  522. */
  523. <<__Native, __NonRx('Randomness')>>
  524. function rand(int $min = 0, ?int $max = null): int;
  525. /**
  526. * @return int - Returns the maximum random value returned by mt_rand()
  527. *
  528. */
  529. <<__IsFoldable, __Native>>
  530. function mt_getrandmax(): int;
  531. /**
  532. * Seeds the random number generator with seed or with a random value if no
  533. * seed is given. As of PHP 4.2.0, there is no need to seed the random number
  534. * generator with srand() or mt_srand() as this is now done automatically.
  535. *
  536. * @param mixed $seed - An optional seed value
  537. *
  538. */
  539. <<__Native, __NonRx('Randomness')>>
  540. function mt_srand(mixed $seed = null): void;
  541. /**
  542. * @param int $min - Optional lowest value to be returned (default: 0)
  543. * @param int $max - Optional highest value to be returned (default:
  544. * mt_getrandmax())
  545. *
  546. * @return int - A random integer value between min (or 0) and max (or
  547. * mt_getrandmax(), inclusive)
  548. *
  549. */
  550. <<__Native, __NonRx('Randomness')>>
  551. function mt_rand(int $min = 0, ?int $max = null): int;
  552. /**
  553. * lcg_value() returns a pseudo random number in the range of (0, 1). The
  554. * function combines two CGs with periods of 2^31 - 85 and 2^31 - 249. The
  555. * period of this function is equal to the product of both primes.
  556. *
  557. * @return float - A pseudo random float value in the range of (0, 1)
  558. *
  559. */
  560. <<__Native, __NonRx('Randomness')>>
  561. function lcg_value(): float;
  562. /**
  563. * intdiv() Integer division.
  564. *
  565. * @param int numerator - Number to be divided.
  566. * @param int divisor - Number which divides the numerator.
  567. *
  568. * @return mixed - The integer division of numerator by divisor. If divisor
  569. * is 0, a DivisionByZeroError exception is thrown. If the numerator is
  570. * PHP_INT_MIN and the divisor is -1, then an ArithmeticError exception
  571. * is thrown.
  572. *
  573. */
  574. <<__IsFoldable, __Native, __Rx>>
  575. function intdiv(int $numerator, int $divisor): mixed;