gmp_gcdext.phpt 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. --TEST--
  2. gmp_gcdext() basic tests
  3. --SKIPIF--
  4. <?php if (!extension_loaded("gmp")) print "skip";
  5. ?>
  6. --FILE--
  7. <?php
  8. $n = gmp_init("34293864345");
  9. $n1 = gmp_init("23434293864345");
  10. $a = array(
  11. array(123,45),
  12. array(4341,9734),
  13. array(23487,333),
  14. array(-234234,-123123),
  15. array(-100,-2234),
  16. array(345,"34587345"),
  17. array(345,"0"),
  18. array("345556456",345873),
  19. array("34545345556456","323432445873"),
  20. array($n, $n1),
  21. );
  22. foreach ($a as $val) {
  23. $r = gmp_gcdext($val[0],$val[1]);
  24. $check = gmp_add(gmp_mul($val[0],$r['s']), gmp_mul($val[1],$r['t']));
  25. var_dump(gmp_strval($r['g']));
  26. var_dump(gmp_strval($check));
  27. }
  28. var_dump(gmp_gcdext($val[0],array()));
  29. var_dump(gmp_gcdext(array(),array()));
  30. var_dump(gmp_gcdext(array(),array(),1));
  31. var_dump(gmp_gcdext(array()));
  32. var_dump(gmp_gcdext());
  33. echo "Done\n";
  34. ?>
  35. --EXPECTF--
  36. string(1) "3"
  37. string(1) "3"
  38. string(1) "1"
  39. string(1) "1"
  40. string(1) "3"
  41. string(1) "3"
  42. string(4) "3003"
  43. string(4) "3003"
  44. string(1) "2"
  45. string(1) "2"
  46. string(2) "15"
  47. string(2) "15"
  48. string(3) "345"
  49. string(3) "345"
  50. string(1) "1"
  51. string(1) "1"
  52. string(1) "1"
  53. string(1) "1"
  54. string(3) "195"
  55. string(3) "195"
  56. Warning: gmp_gcdext(): Unable to convert variable to GMP - wrong type in %s on line %d
  57. bool(false)
  58. Warning: gmp_gcdext(): Unable to convert variable to GMP - wrong type in %s on line %d
  59. bool(false)
  60. Warning: gmp_gcdext() expects exactly 2 parameters, 3 given in %s on line %d
  61. NULL
  62. Warning: gmp_gcdext() expects exactly 2 parameters, 1 given in %s on line %d
  63. NULL
  64. Warning: gmp_gcdext() expects exactly 2 parameters, 0 given in %s on line %d
  65. NULL
  66. Done