str2num_formatting.phpt 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. --TEST--
  2. bcmath lib arguments formatting
  3. --DESCRIPTION--
  4. 1 and 2 argument of bcadd/bcsub/bcmul/bcdiv/bcmod/bcpowmod/bcpow/bccomp (last one works different then others internally);
  5. 1 argument of bcsqrt
  6. All of the name above must be well-formed
  7. --EXTENSIONS--
  8. bcmath
  9. --FILE--
  10. <?php
  11. echo bcadd("1", "2"),"\n";
  12. echo bcadd("1.1", "2", 2),"\n";
  13. echo bcadd("", "2", 2),"\n";
  14. echo bcadd("+0", "2"), "\n";
  15. echo bcadd("-0", "2"), "\n";
  16. echo "\n";
  17. try {
  18. echo bcadd(" 0", "2");
  19. } catch (\ValueError $e) {
  20. echo $e->getMessage() . PHP_EOL;
  21. }
  22. try {
  23. echo bcadd("1e1", "2");
  24. } catch (\ValueError $e) {
  25. echo $e->getMessage() . PHP_EOL;
  26. }
  27. try {
  28. echo bcadd("1,1", "2");
  29. } catch (\ValueError $e) {
  30. echo $e->getMessage() . PHP_EOL;
  31. }
  32. try {
  33. echo bcadd("Hello", "2");
  34. } catch (\ValueError $e) {
  35. echo $e->getMessage() . PHP_EOL;
  36. }
  37. try {
  38. echo bcadd("1 1", "2");
  39. } catch (\ValueError $e) {
  40. echo $e->getMessage() . PHP_EOL;
  41. }
  42. try {
  43. echo bcadd("1.a", "2");
  44. } catch (\ValueError $e) {
  45. echo $e->getMessage() . PHP_EOL;
  46. }
  47. echo "\n";
  48. echo bccomp("1", "2"),"\n";
  49. echo bccomp("1.1", "2", 2),"\n";
  50. echo bccomp("", "2"),"\n";
  51. echo bccomp("+0", "2"), "\n";
  52. echo bccomp("-0", "2"), "\n";
  53. echo "\n";
  54. try {
  55. echo bccomp(" 0", "2");
  56. } catch (\ValueError $e) {
  57. echo $e->getMessage() . PHP_EOL;
  58. }
  59. try {
  60. echo bccomp("1e1", "2");
  61. } catch (\ValueError $e) {
  62. echo $e->getMessage() . PHP_EOL;
  63. }
  64. try {
  65. echo bccomp("1,1", "2");
  66. } catch (\ValueError $e) {
  67. echo $e->getMessage() . PHP_EOL;
  68. }
  69. try {
  70. echo bccomp("Hello", "2");
  71. } catch (\ValueError $e) {
  72. echo $e->getMessage() . PHP_EOL;
  73. }
  74. try {
  75. echo bccomp("1 1", "2");
  76. } catch (\ValueError $e) {
  77. echo $e->getMessage() . PHP_EOL;
  78. }
  79. ?>
  80. --EXPECT--
  81. 3
  82. 3.10
  83. 2.00
  84. 2
  85. 2
  86. bcadd(): Argument #1 ($num1) is not well-formed
  87. bcadd(): Argument #1 ($num1) is not well-formed
  88. bcadd(): Argument #1 ($num1) is not well-formed
  89. bcadd(): Argument #1 ($num1) is not well-formed
  90. bcadd(): Argument #1 ($num1) is not well-formed
  91. bcadd(): Argument #1 ($num1) is not well-formed
  92. -1
  93. -1
  94. -1
  95. -1
  96. -1
  97. bccomp(): Argument #1 ($num1) is not well-formed
  98. bccomp(): Argument #1 ($num1) is not well-formed
  99. bccomp(): Argument #1 ($num1) is not well-formed
  100. bccomp(): Argument #1 ($num1) is not well-formed
  101. bccomp(): Argument #1 ($num1) is not well-formed