mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
[RFC] Support object types in BCMath (#13741)
Added BcMath\Number class. It is an immutable object, has methods that are equivalent to existing BCMath calculation functions, and can also be calculated using operators. The existing BCMath function returned a string for each calculation, but this class returns an object. RFC: https://wiki.php.net/rfc/support_object_type_in_bcmath, https://wiki.php.net/rfc/fix_up_bcmath_number_class --------- Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
This commit is contained in:
parent
13f041163c
commit
fad899e566
84 changed files with 8063 additions and 37 deletions
1
NEWS
1
NEWS
|
@ -5,6 +5,7 @@ PHP NEWS
|
|||
- BCMath:
|
||||
. Fixed LONG_MAX in BCMath ext. (Saki Takamachi)
|
||||
. Fixed bcdiv() div by one. (Saki Takamachi)
|
||||
. [RFC] Support object types in BCMath. (Saki Takamachi)
|
||||
|
||||
- Core:
|
||||
. Fixed bug GH-15330 (Do not scan generator frames more than once). (Arnaud)
|
||||
|
|
|
@ -873,6 +873,15 @@ PHP 8.4 UPGRADE NOTES
|
|||
7. New Classes and Interfaces
|
||||
========================================
|
||||
|
||||
- BCMath:
|
||||
. Added BcMath\Number class. It is an immutable object, has methods that are
|
||||
equivalent to existing BCMath calculation functions, and can also be calculated
|
||||
using operators.
|
||||
The existing BCMath function returned a string for each calculation, but this
|
||||
class returns an object.
|
||||
RFC: https://wiki.php.net/rfc/support_object_type_in_bcmath,
|
||||
https://wiki.php.net/rfc/fix_up_bcmath_number_class
|
||||
|
||||
- Core:
|
||||
. New RequestParseBodyException.
|
||||
RFC: https://wiki.php.net/rfc/rfc1867-non-post
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,39 +2,86 @@
|
|||
|
||||
/** @generate-class-entries */
|
||||
|
||||
/** @refcount 1 */
|
||||
function bcadd(string $num1, string $num2, ?int $scale = null): string {}
|
||||
namespace
|
||||
{
|
||||
/** @refcount 1 */
|
||||
function bcadd(string $num1, string $num2, ?int $scale = null): string {}
|
||||
|
||||
/** @refcount 1 */
|
||||
function bcsub(string $num1, string $num2, ?int $scale = null): string {}
|
||||
/** @refcount 1 */
|
||||
function bcsub(string $num1, string $num2, ?int $scale = null): string {}
|
||||
|
||||
/** @refcount 1 */
|
||||
function bcmul(string $num1, string $num2, ?int $scale = null): string {}
|
||||
/** @refcount 1 */
|
||||
function bcmul(string $num1, string $num2, ?int $scale = null): string {}
|
||||
|
||||
/** @refcount 1 */
|
||||
function bcdiv(string $num1, string $num2, ?int $scale = null): string {}
|
||||
/** @refcount 1 */
|
||||
function bcdiv(string $num1, string $num2, ?int $scale = null): string {}
|
||||
|
||||
/** @refcount 1 */
|
||||
function bcmod(string $num1, string $num2, ?int $scale = null): string {}
|
||||
/** @refcount 1 */
|
||||
function bcmod(string $num1, string $num2, ?int $scale = null): string {}
|
||||
|
||||
/** @refcount 1 */
|
||||
function bcpowmod(string $num, string $exponent, string $modulus, ?int $scale = null): string {}
|
||||
/** @refcount 1 */
|
||||
function bcpowmod(string $num, string $exponent, string $modulus, ?int $scale = null): string {}
|
||||
|
||||
/** @refcount 1 */
|
||||
function bcpow(string $num, string $exponent, ?int $scale = null): string {}
|
||||
/** @refcount 1 */
|
||||
function bcpow(string $num, string $exponent, ?int $scale = null): string {}
|
||||
|
||||
/** @refcount 1 */
|
||||
function bcsqrt(string $num, ?int $scale = null): string {}
|
||||
/** @refcount 1 */
|
||||
function bcsqrt(string $num, ?int $scale = null): string {}
|
||||
|
||||
function bccomp(string $num1, string $num2, ?int $scale = null): int {}
|
||||
function bccomp(string $num1, string $num2, ?int $scale = null): int {}
|
||||
|
||||
function bcscale(?int $scale = null): int {}
|
||||
function bcscale(?int $scale = null): int {}
|
||||
|
||||
/** @refcount 1 */
|
||||
function bcfloor(string $num): string {}
|
||||
/** @refcount 1 */
|
||||
function bcfloor(string $num): string {}
|
||||
|
||||
/** @refcount 1 */
|
||||
function bcceil(string $num): string {}
|
||||
/** @refcount 1 */
|
||||
function bcceil(string $num): string {}
|
||||
|
||||
/** @refcount 1 */
|
||||
function bcround(string $num, int $precision = 0, RoundingMode $mode = RoundingMode::HalfAwayFromZero): string {}
|
||||
/** @refcount 1 */
|
||||
function bcround(string $num, int $precision = 0, RoundingMode $mode = RoundingMode::HalfAwayFromZero): string {}
|
||||
}
|
||||
|
||||
namespace BcMath
|
||||
{
|
||||
/** @strict-properties */
|
||||
final readonly class Number implements \Stringable
|
||||
{
|
||||
/** @virtual */
|
||||
public string $value;
|
||||
/** @virtual */
|
||||
public int $scale;
|
||||
|
||||
public function __construct(string|int $num) {}
|
||||
|
||||
public function add(Number|string|int $num, ?int $scale = null): Number {}
|
||||
|
||||
public function sub(Number|string|int $num, ?int $scale = null): Number {}
|
||||
|
||||
public function mul(Number|string|int $num, ?int $scale = null): Number {}
|
||||
|
||||
public function div(Number|string|int $num, ?int $scale = null): Number {}
|
||||
|
||||
public function mod(Number|string|int $num, ?int $scale = null): Number {}
|
||||
|
||||
public function powmod(Number|string|int $exponent, Number|string|int $modulus, ?int $scale = null): Number {}
|
||||
|
||||
public function pow(Number|string|int $exponent, ?int $scale = null): Number {}
|
||||
|
||||
public function sqrt(?int $scale = null): Number {}
|
||||
|
||||
public function floor(): Number {}
|
||||
|
||||
public function ceil(): Number {}
|
||||
|
||||
public function round(int $precision = 0, \RoundingMode $mode = \RoundingMode::HalfAwayFromZero): Number {}
|
||||
|
||||
public function compare(Number|string|int $num, ?int $scale = null): int {}
|
||||
|
||||
public function __toString(): string {}
|
||||
|
||||
public function __serialize(): array {}
|
||||
|
||||
public function __unserialize(array $data): void {}
|
||||
}
|
||||
}
|
||||
|
|
118
ext/bcmath/bcmath_arginfo.h
generated
118
ext/bcmath/bcmath_arginfo.h
generated
|
@ -1,5 +1,5 @@
|
|||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: 7439a5fca649b8c4df317b0da1416c8fe59faf72 */
|
||||
* Stub hash: f3101bbd25da90d97801d53ea673789d1ce4f6a1 */
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcadd, 0, 2, IS_STRING, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, num1, IS_STRING, 0)
|
||||
|
@ -55,6 +55,63 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcround, 0, 1, IS_STRING, 0)
|
|||
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, mode, RoundingMode, 0, "RoundingMode::HalfAwayFromZero")
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_BcMath_Number___construct, 0, 0, 1)
|
||||
ZEND_ARG_TYPE_MASK(0, num, MAY_BE_STRING|MAY_BE_LONG, NULL)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_BcMath_Number_add, 0, 1, BcMath\\\116umber, 0)
|
||||
ZEND_ARG_OBJ_TYPE_MASK(0, num, BcMath\\\116umber, MAY_BE_STRING|MAY_BE_LONG, NULL)
|
||||
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, scale, IS_LONG, 1, "null")
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_class_BcMath_Number_sub arginfo_class_BcMath_Number_add
|
||||
|
||||
#define arginfo_class_BcMath_Number_mul arginfo_class_BcMath_Number_add
|
||||
|
||||
#define arginfo_class_BcMath_Number_div arginfo_class_BcMath_Number_add
|
||||
|
||||
#define arginfo_class_BcMath_Number_mod arginfo_class_BcMath_Number_add
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_BcMath_Number_powmod, 0, 2, BcMath\\\116umber, 0)
|
||||
ZEND_ARG_OBJ_TYPE_MASK(0, exponent, BcMath\\\116umber, MAY_BE_STRING|MAY_BE_LONG, NULL)
|
||||
ZEND_ARG_OBJ_TYPE_MASK(0, modulus, BcMath\\\116umber, MAY_BE_STRING|MAY_BE_LONG, NULL)
|
||||
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, scale, IS_LONG, 1, "null")
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_BcMath_Number_pow, 0, 1, BcMath\\\116umber, 0)
|
||||
ZEND_ARG_OBJ_TYPE_MASK(0, exponent, BcMath\\\116umber, MAY_BE_STRING|MAY_BE_LONG, NULL)
|
||||
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, scale, IS_LONG, 1, "null")
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_BcMath_Number_sqrt, 0, 0, BcMath\\\116umber, 0)
|
||||
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, scale, IS_LONG, 1, "null")
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_BcMath_Number_floor, 0, 0, BcMath\\\116umber, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_class_BcMath_Number_ceil arginfo_class_BcMath_Number_floor
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_BcMath_Number_round, 0, 0, BcMath\\\116umber, 0)
|
||||
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, precision, IS_LONG, 0, "0")
|
||||
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, mode, RoundingMode, 0, "RoundingMode::HalfAwayFromZero")
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_BcMath_Number_compare, 0, 1, IS_LONG, 0)
|
||||
ZEND_ARG_OBJ_TYPE_MASK(0, num, BcMath\\\116umber, MAY_BE_STRING|MAY_BE_LONG, NULL)
|
||||
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, scale, IS_LONG, 1, "null")
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_BcMath_Number___toString, 0, 0, IS_STRING, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_BcMath_Number___serialize, 0, 0, IS_ARRAY, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_BcMath_Number___unserialize, 0, 1, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_FUNCTION(bcadd);
|
||||
ZEND_FUNCTION(bcsub);
|
||||
ZEND_FUNCTION(bcmul);
|
||||
|
@ -68,6 +125,22 @@ ZEND_FUNCTION(bcscale);
|
|||
ZEND_FUNCTION(bcfloor);
|
||||
ZEND_FUNCTION(bcceil);
|
||||
ZEND_FUNCTION(bcround);
|
||||
ZEND_METHOD(BcMath_Number, __construct);
|
||||
ZEND_METHOD(BcMath_Number, add);
|
||||
ZEND_METHOD(BcMath_Number, sub);
|
||||
ZEND_METHOD(BcMath_Number, mul);
|
||||
ZEND_METHOD(BcMath_Number, div);
|
||||
ZEND_METHOD(BcMath_Number, mod);
|
||||
ZEND_METHOD(BcMath_Number, powmod);
|
||||
ZEND_METHOD(BcMath_Number, pow);
|
||||
ZEND_METHOD(BcMath_Number, sqrt);
|
||||
ZEND_METHOD(BcMath_Number, floor);
|
||||
ZEND_METHOD(BcMath_Number, ceil);
|
||||
ZEND_METHOD(BcMath_Number, round);
|
||||
ZEND_METHOD(BcMath_Number, compare);
|
||||
ZEND_METHOD(BcMath_Number, __toString);
|
||||
ZEND_METHOD(BcMath_Number, __serialize);
|
||||
ZEND_METHOD(BcMath_Number, __unserialize);
|
||||
|
||||
static const zend_function_entry ext_functions[] = {
|
||||
ZEND_FE(bcadd, arginfo_bcadd)
|
||||
|
@ -85,3 +158,46 @@ static const zend_function_entry ext_functions[] = {
|
|||
ZEND_FE(bcround, arginfo_bcround)
|
||||
ZEND_FE_END
|
||||
};
|
||||
|
||||
static const zend_function_entry class_BcMath_Number_methods[] = {
|
||||
ZEND_ME(BcMath_Number, __construct, arginfo_class_BcMath_Number___construct, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(BcMath_Number, add, arginfo_class_BcMath_Number_add, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(BcMath_Number, sub, arginfo_class_BcMath_Number_sub, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(BcMath_Number, mul, arginfo_class_BcMath_Number_mul, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(BcMath_Number, div, arginfo_class_BcMath_Number_div, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(BcMath_Number, mod, arginfo_class_BcMath_Number_mod, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(BcMath_Number, powmod, arginfo_class_BcMath_Number_powmod, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(BcMath_Number, pow, arginfo_class_BcMath_Number_pow, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(BcMath_Number, sqrt, arginfo_class_BcMath_Number_sqrt, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(BcMath_Number, floor, arginfo_class_BcMath_Number_floor, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(BcMath_Number, ceil, arginfo_class_BcMath_Number_ceil, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(BcMath_Number, round, arginfo_class_BcMath_Number_round, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(BcMath_Number, compare, arginfo_class_BcMath_Number_compare, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(BcMath_Number, __toString, arginfo_class_BcMath_Number___toString, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(BcMath_Number, __serialize, arginfo_class_BcMath_Number___serialize, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(BcMath_Number, __unserialize, arginfo_class_BcMath_Number___unserialize, ZEND_ACC_PUBLIC)
|
||||
ZEND_FE_END
|
||||
};
|
||||
|
||||
static zend_class_entry *register_class_BcMath_Number(zend_class_entry *class_entry_Stringable)
|
||||
{
|
||||
zend_class_entry ce, *class_entry;
|
||||
|
||||
INIT_NS_CLASS_ENTRY(ce, "BcMath", "Number", class_BcMath_Number_methods);
|
||||
class_entry = zend_register_internal_class_with_flags(&ce, NULL, ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES|ZEND_ACC_READONLY_CLASS);
|
||||
zend_class_implements(class_entry, 1, class_entry_Stringable);
|
||||
|
||||
zval property_value_default_value;
|
||||
ZVAL_UNDEF(&property_value_default_value);
|
||||
zend_string *property_value_name = zend_string_init("value", sizeof("value") - 1, 1);
|
||||
zend_declare_typed_property(class_entry, property_value_name, &property_value_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY|ZEND_ACC_VIRTUAL, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
|
||||
zend_string_release(property_value_name);
|
||||
|
||||
zval property_scale_default_value;
|
||||
ZVAL_UNDEF(&property_scale_default_value);
|
||||
zend_string *property_scale_name = zend_string_init("scale", sizeof("scale") - 1, 1);
|
||||
zend_declare_typed_property(class_entry, property_scale_name, &property_scale_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY|ZEND_ACC_VIRTUAL, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
|
||||
zend_string_release(property_scale_name);
|
||||
|
||||
return class_entry;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ if test "$PHP_BCMATH" != "no"; then
|
|||
libbcmath/src/divmod.c
|
||||
libbcmath/src/doaddsub.c
|
||||
libbcmath/src/floor_or_ceil.c
|
||||
libbcmath/src/long2num.c
|
||||
libbcmath/src/init.c
|
||||
libbcmath/src/int2num.c
|
||||
libbcmath/src/nearzero.c
|
||||
|
|
|
@ -5,7 +5,7 @@ ARG_ENABLE("bcmath", "bc style precision math functions", "yes");
|
|||
if (PHP_BCMATH == "yes") {
|
||||
EXTENSION("bcmath", "bcmath.c", null, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
|
||||
ADD_SOURCES("ext/bcmath/libbcmath/src", "add.c div.c init.c neg.c \
|
||||
raisemod.c sub.c compare.c divmod.c int2num.c \
|
||||
raisemod.c sub.c compare.c divmod.c int2num.c long2num.c \
|
||||
num2long.c recmul.c sqrt.c zero.c doaddsub.c \
|
||||
floor_or_ceil.c nearzero.c num2str.c raise.c rmzero.c str2num.c \
|
||||
round.c convert.c", "bcmath");
|
||||
|
|
|
@ -98,7 +98,9 @@ static inline bc_num bc_copy_num(bc_num num)
|
|||
|
||||
void bc_init_num(bc_num *num);
|
||||
|
||||
bool bc_str2num(bc_num *num, const char *str, const char *end, size_t scale, bool auto_scale);
|
||||
bool bc_str2num(bc_num *num, const char *str, const char *end, size_t scale, size_t *full_scale, bool auto_scale);
|
||||
|
||||
bc_num bc_long2num(zend_long lval);
|
||||
|
||||
zend_string *bc_num2str_ex(bc_num num, size_t scale);
|
||||
|
||||
|
@ -122,6 +124,8 @@ bool bc_is_near_zero(bc_num num, size_t scale);
|
|||
|
||||
bool bc_is_neg(bc_num num);
|
||||
|
||||
void bc_rm_trailing_zeros(bc_num num);
|
||||
|
||||
bc_num bc_add(bc_num n1, bc_num n2, size_t scale_min);
|
||||
|
||||
#define bc_add_ex(n1, n2, result, scale_min) do { \
|
||||
|
|
|
@ -70,6 +70,12 @@ bool bc_divmod(bc_num num1, bc_num num2, bc_num *quot, bc_num *rem, size_t scale
|
|||
*quot = quotient;
|
||||
}
|
||||
|
||||
/* The value of rscale changes during processing. Here we use the value of scale. It's not a typo. */
|
||||
(*rem)->n_scale = MIN(scale, (*rem)->n_scale);
|
||||
if (bc_is_zero(*rem)) {
|
||||
(*rem)->n_sign = PLUS;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
59
ext/bcmath/libbcmath/src/long2num.c
Normal file
59
ext/bcmath/libbcmath/src/long2num.c
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.01 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| https://www.php.net/license/3_01.txt |
|
||||
| If you did not receive a copy of the PHP license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Authors: Saki Takamachi <saki@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#include "bcmath.h"
|
||||
#include <stdbool.h>
|
||||
#include "convert.h"
|
||||
|
||||
#define BC_LONG_MAX_DIGITS (sizeof(LONG_MIN_DIGITS) - 1)
|
||||
|
||||
bc_num bc_long2num(zend_long lval)
|
||||
{
|
||||
bc_num num;
|
||||
|
||||
if (UNEXPECTED(lval == 0)) {
|
||||
num = bc_copy_num(BCG(_zero_));
|
||||
return num;
|
||||
}
|
||||
|
||||
bool negative = lval < 0;
|
||||
if (UNEXPECTED(lval == ZEND_LONG_MIN)) {
|
||||
num = bc_new_num_nonzeroed(BC_LONG_MAX_DIGITS, 0);
|
||||
const char *ptr = LONG_MIN_DIGITS;
|
||||
bc_copy_and_toggle_bcd(num->n_value, ptr, ptr + BC_LONG_MAX_DIGITS);
|
||||
num->n_sign = MINUS;
|
||||
return num;
|
||||
} else if (negative) {
|
||||
lval = -lval;
|
||||
}
|
||||
|
||||
zend_long tmp = lval;
|
||||
size_t len = 0;
|
||||
while (tmp > 0) {
|
||||
tmp /= BASE;
|
||||
len++;
|
||||
}
|
||||
|
||||
num = bc_new_num_nonzeroed(len, 0);
|
||||
char *ptr = num->n_value + len - 1;
|
||||
for (; len > 0; len--) {
|
||||
*ptr-- = lval % BASE;
|
||||
lval /= BASE;
|
||||
}
|
||||
num->n_sign = negative ? MINUS : PLUS;
|
||||
|
||||
return num;
|
||||
}
|
|
@ -94,9 +94,7 @@ void bc_raise(bc_num num1, long exponent, bc_num *result, size_t scale)
|
|||
} else {
|
||||
bc_free_num (result);
|
||||
*result = temp;
|
||||
if ((*result)->n_scale > rscale) {
|
||||
(*result)->n_scale = rscale;
|
||||
}
|
||||
(*result)->n_scale = MIN(scale, (*result)->n_scale);
|
||||
}
|
||||
bc_free_num (&power);
|
||||
}
|
||||
|
|
|
@ -44,3 +44,16 @@ void _bc_rm_leading_zeros(bc_num num)
|
|||
num->n_len--;
|
||||
}
|
||||
}
|
||||
|
||||
void bc_rm_trailing_zeros(bc_num num)
|
||||
{
|
||||
if (num->n_scale == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
char *end = num->n_value + num->n_len + num->n_scale - 1;
|
||||
while (*end == 0 && num->n_scale > 0) {
|
||||
num->n_scale--;
|
||||
end--;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ static inline const char *bc_skip_zero_reverse(const char *scanner, const char *
|
|||
}
|
||||
|
||||
/* Assumes `num` points to NULL, i.e. does yet not hold a number. */
|
||||
bool bc_str2num(bc_num *num, const char *str, const char *end, size_t scale, bool auto_scale)
|
||||
bool bc_str2num(bc_num *num, const char *str, const char *end, size_t scale, size_t *full_scale, bool auto_scale)
|
||||
{
|
||||
size_t str_scale = 0;
|
||||
const char *ptr = str;
|
||||
|
@ -143,6 +143,9 @@ bool bc_str2num(bc_num *num, const char *str, const char *end, size_t scale, boo
|
|||
fractional_ptr = fractional_end = decimal_point + 1;
|
||||
/* For strings that end with a decimal point, such as "012." */
|
||||
if (UNEXPECTED(*fractional_ptr == '\0')) {
|
||||
if (full_scale) {
|
||||
*full_scale = 0;
|
||||
}
|
||||
goto after_fractional;
|
||||
}
|
||||
|
||||
|
@ -153,6 +156,10 @@ bool bc_str2num(bc_num *num, const char *str, const char *end, size_t scale, boo
|
|||
goto fail;
|
||||
}
|
||||
|
||||
if (full_scale) {
|
||||
*full_scale = fractional_end - fractional_ptr;
|
||||
}
|
||||
|
||||
/* Exclude trailing zeros. */
|
||||
fractional_end = bc_skip_zero_reverse(fractional_end, fractional_ptr);
|
||||
|
||||
|
@ -167,6 +174,10 @@ bool bc_str2num(bc_num *num, const char *str, const char *end, size_t scale, boo
|
|||
fractional_end -= str_scale - scale;
|
||||
str_scale = scale;
|
||||
}
|
||||
} else {
|
||||
if (full_scale) {
|
||||
*full_scale = 0;
|
||||
}
|
||||
}
|
||||
|
||||
after_fractional:
|
||||
|
|
|
@ -45,4 +45,14 @@ ZEND_TSRMLS_CACHE_EXTERN()
|
|||
ZEND_EXTERN_MODULE_GLOBALS(bcmath)
|
||||
#define BCG(v) ZEND_MODULE_GLOBALS_ACCESSOR(bcmath, v)
|
||||
|
||||
/* Maximum number of digits to extend when scale needs to be extended, such as in undivisible division */
|
||||
#define BC_MATH_NUMBER_EXPAND_SCALE 10
|
||||
|
||||
typedef struct _bcmath_number_obj_t {
|
||||
zend_string *value;
|
||||
size_t scale;
|
||||
bc_num num;
|
||||
zend_object std;
|
||||
} bcmath_number_obj_t;
|
||||
|
||||
#endif /* PHP_BCMATH_H */
|
||||
|
|
277
ext/bcmath/tests/number/cast.phpt
Normal file
277
ext/bcmath/tests/number/cast.phpt
Normal file
|
@ -0,0 +1,277 @@
|
|||
--TEST--
|
||||
BcMath\Number cast
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
'0',
|
||||
'0.0',
|
||||
'2',
|
||||
'1234',
|
||||
'12.0004',
|
||||
'0.1230',
|
||||
1,
|
||||
12345,
|
||||
'-0',
|
||||
'-0.0',
|
||||
'-2',
|
||||
'-1234',
|
||||
'-12.0004',
|
||||
'-0.1230',
|
||||
-1,
|
||||
-12345,
|
||||
];
|
||||
|
||||
foreach ($values as $value) {
|
||||
$num = new BcMath\Number($value);
|
||||
echo "========== {$value} ==========\n";
|
||||
var_dump([
|
||||
'bool' => (bool) $num,
|
||||
'string' => (string) $num,
|
||||
'array' => (array) $num,
|
||||
]);
|
||||
echo "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
========== 0 ==========
|
||||
array(3) {
|
||||
["bool"]=>
|
||||
bool(false)
|
||||
["string"]=>
|
||||
string(1) "0"
|
||||
["array"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
}
|
||||
|
||||
========== 0.0 ==========
|
||||
array(3) {
|
||||
["bool"]=>
|
||||
bool(false)
|
||||
["string"]=>
|
||||
string(3) "0.0"
|
||||
["array"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
string(3) "0.0"
|
||||
["scale"]=>
|
||||
int(1)
|
||||
}
|
||||
}
|
||||
|
||||
========== 2 ==========
|
||||
array(3) {
|
||||
["bool"]=>
|
||||
bool(true)
|
||||
["string"]=>
|
||||
string(1) "2"
|
||||
["array"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
string(1) "2"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
}
|
||||
|
||||
========== 1234 ==========
|
||||
array(3) {
|
||||
["bool"]=>
|
||||
bool(true)
|
||||
["string"]=>
|
||||
string(4) "1234"
|
||||
["array"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
string(4) "1234"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
}
|
||||
|
||||
========== 12.0004 ==========
|
||||
array(3) {
|
||||
["bool"]=>
|
||||
bool(true)
|
||||
["string"]=>
|
||||
string(7) "12.0004"
|
||||
["array"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
string(7) "12.0004"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
}
|
||||
|
||||
========== 0.1230 ==========
|
||||
array(3) {
|
||||
["bool"]=>
|
||||
bool(true)
|
||||
["string"]=>
|
||||
string(6) "0.1230"
|
||||
["array"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
string(6) "0.1230"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
}
|
||||
|
||||
========== 1 ==========
|
||||
array(3) {
|
||||
["bool"]=>
|
||||
bool(true)
|
||||
["string"]=>
|
||||
string(1) "1"
|
||||
["array"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
}
|
||||
|
||||
========== 12345 ==========
|
||||
array(3) {
|
||||
["bool"]=>
|
||||
bool(true)
|
||||
["string"]=>
|
||||
string(5) "12345"
|
||||
["array"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
string(5) "12345"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
}
|
||||
|
||||
========== -0 ==========
|
||||
array(3) {
|
||||
["bool"]=>
|
||||
bool(false)
|
||||
["string"]=>
|
||||
string(1) "0"
|
||||
["array"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
}
|
||||
|
||||
========== -0.0 ==========
|
||||
array(3) {
|
||||
["bool"]=>
|
||||
bool(false)
|
||||
["string"]=>
|
||||
string(3) "0.0"
|
||||
["array"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
string(3) "0.0"
|
||||
["scale"]=>
|
||||
int(1)
|
||||
}
|
||||
}
|
||||
|
||||
========== -2 ==========
|
||||
array(3) {
|
||||
["bool"]=>
|
||||
bool(true)
|
||||
["string"]=>
|
||||
string(2) "-2"
|
||||
["array"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
string(2) "-2"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
}
|
||||
|
||||
========== -1234 ==========
|
||||
array(3) {
|
||||
["bool"]=>
|
||||
bool(true)
|
||||
["string"]=>
|
||||
string(5) "-1234"
|
||||
["array"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
string(5) "-1234"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
}
|
||||
|
||||
========== -12.0004 ==========
|
||||
array(3) {
|
||||
["bool"]=>
|
||||
bool(true)
|
||||
["string"]=>
|
||||
string(8) "-12.0004"
|
||||
["array"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
string(8) "-12.0004"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
}
|
||||
|
||||
========== -0.1230 ==========
|
||||
array(3) {
|
||||
["bool"]=>
|
||||
bool(true)
|
||||
["string"]=>
|
||||
string(7) "-0.1230"
|
||||
["array"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
string(7) "-0.1230"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
}
|
||||
|
||||
========== -1 ==========
|
||||
array(3) {
|
||||
["bool"]=>
|
||||
bool(true)
|
||||
["string"]=>
|
||||
string(2) "-1"
|
||||
["array"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
string(2) "-1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
}
|
||||
|
||||
========== -12345 ==========
|
||||
array(3) {
|
||||
["bool"]=>
|
||||
bool(true)
|
||||
["string"]=>
|
||||
string(6) "-12345"
|
||||
["array"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
string(6) "-12345"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
}
|
14
ext/bcmath/tests/number/cast_warning.phpt
Normal file
14
ext/bcmath/tests/number/cast_warning.phpt
Normal file
|
@ -0,0 +1,14 @@
|
|||
--TEST--
|
||||
BcMath\Number cast warning
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
$num = new BcMath\Number(1);
|
||||
(int) $num;
|
||||
(float) $num;
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: Object of class BcMath\Number could not be converted to int in %s
|
||||
|
||||
Warning: Object of class BcMath\Number could not be converted to float in %s
|
13
ext/bcmath/tests/number/class_extends_error.phpt
Normal file
13
ext/bcmath/tests/number/class_extends_error.phpt
Normal file
|
@ -0,0 +1,13 @@
|
|||
--TEST--
|
||||
BcMath\Number class extends error
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class Child extends \BcMath\Number{}
|
||||
|
||||
$child = new Child(1);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Class Child cannot extend final class BcMath\Number in %s
|
38
ext/bcmath/tests/number/clone.phpt
Normal file
38
ext/bcmath/tests/number/clone.phpt
Normal file
|
@ -0,0 +1,38 @@
|
|||
--TEST--
|
||||
BcMath\Number clone
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
'0',
|
||||
'0.0',
|
||||
'2',
|
||||
'1234',
|
||||
'12.0004',
|
||||
'0.1230',
|
||||
1,
|
||||
12345,
|
||||
'-0',
|
||||
'-0.0',
|
||||
'-2',
|
||||
'-1234',
|
||||
'-12.0004',
|
||||
'-0.1230',
|
||||
-1,
|
||||
-12345,
|
||||
];
|
||||
|
||||
foreach ($values as $value) {
|
||||
$num = new BcMath\Number($value);
|
||||
$clone = clone $num;
|
||||
if ($num->value !== $clone->value || $num->scale !== $clone->scale || $num === $clone) {
|
||||
echo "Result is incorrect.\n";
|
||||
var_dump($num, $clone);
|
||||
}
|
||||
}
|
||||
echo 'done!';
|
||||
?>
|
||||
--EXPECT--
|
||||
done!
|
142
ext/bcmath/tests/number/construct_32bit.phpt
Normal file
142
ext/bcmath/tests/number/construct_32bit.phpt
Normal file
|
@ -0,0 +1,142 @@
|
|||
--TEST--
|
||||
BcMath\Number construct 32 bit
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (PHP_INT_MAX > 2147483647) {
|
||||
die('skip only 32 bit');
|
||||
}
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
'0',
|
||||
'0.00',
|
||||
'.1',
|
||||
'0.1',
|
||||
'0.20',
|
||||
'0.00000030',
|
||||
'1234.0',
|
||||
'123450',
|
||||
'',
|
||||
'-',
|
||||
'.',
|
||||
0,
|
||||
123,
|
||||
2147483646,
|
||||
PHP_INT_MAX,
|
||||
-2147483647,
|
||||
PHP_INT_MIN,
|
||||
];
|
||||
|
||||
foreach ($values as $value) {
|
||||
$num = new BcMath\Number($value);
|
||||
var_dump($num);
|
||||
unset($num);
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(3) "0.1"
|
||||
["scale"]=>
|
||||
int(1)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(3) "0.1"
|
||||
["scale"]=>
|
||||
int(1)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.20"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(10) "0.00000030"
|
||||
["scale"]=>
|
||||
int(8)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(6) "1234.0"
|
||||
["scale"]=>
|
||||
int(1)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(6) "123450"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(3) "123"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(10) "2147483646"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(10) "2147483647"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(11) "-2147483647"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(11) "-2147483648"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
142
ext/bcmath/tests/number/construct_64bit.phpt
Normal file
142
ext/bcmath/tests/number/construct_64bit.phpt
Normal file
|
@ -0,0 +1,142 @@
|
|||
--TEST--
|
||||
BcMath\Number construct 64 bit
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (PHP_INT_MAX <= 2147483647) {
|
||||
die('skip only 64 bit');
|
||||
}
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
'0',
|
||||
'0.00',
|
||||
'.1',
|
||||
'0.1',
|
||||
'0.20',
|
||||
'0.00000030',
|
||||
'1234.0',
|
||||
'123450',
|
||||
'',
|
||||
'-',
|
||||
'.',
|
||||
0,
|
||||
123,
|
||||
9223372036854775806,
|
||||
PHP_INT_MAX,
|
||||
-9223372036854775807,
|
||||
PHP_INT_MIN,
|
||||
];
|
||||
|
||||
foreach ($values as $value) {
|
||||
$num = new BcMath\Number($value);
|
||||
var_dump($num);
|
||||
unset($num);
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(3) "0.1"
|
||||
["scale"]=>
|
||||
int(1)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(3) "0.1"
|
||||
["scale"]=>
|
||||
int(1)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.20"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(10) "0.00000030"
|
||||
["scale"]=>
|
||||
int(8)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(6) "1234.0"
|
||||
["scale"]=>
|
||||
int(1)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(6) "123450"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(3) "123"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(19) "9223372036854775806"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(19) "9223372036854775807"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(20) "-9223372036854775807"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(20) "-9223372036854775808"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
23
ext/bcmath/tests/number/construct_error.phpt
Normal file
23
ext/bcmath/tests/number/construct_error.phpt
Normal file
|
@ -0,0 +1,23 @@
|
|||
--TEST--
|
||||
BcMath\Number construct error
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
try {
|
||||
$num = new BcMath\Number('1');
|
||||
$num->__construct(5);
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num = new BcMath\Number('a');
|
||||
var_dump($num);
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
Cannot modify readonly property BcMath\Number::$value
|
||||
BcMath\Number::__construct(): Argument #1 ($num) is not well-formed
|
17
ext/bcmath/tests/number/construct_float.phpt
Normal file
17
ext/bcmath/tests/number/construct_float.phpt
Normal file
|
@ -0,0 +1,17 @@
|
|||
--TEST--
|
||||
BcMath\Number construct float
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
$num = new BcMath\Number(0.1234);
|
||||
var_dump($num);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Deprecated: Implicit conversion from float 0.1234 to int loses precision in %s
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
142
ext/bcmath/tests/number/methods/add.phpt
Normal file
142
ext/bcmath/tests/number/methods/add.phpt
Normal file
|
@ -0,0 +1,142 @@
|
|||
--TEST--
|
||||
BcMath\Number add()
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values1 = ['100.012', '-100.012'];
|
||||
|
||||
$values2 = [
|
||||
[100, 'int'],
|
||||
[-30, 'int'],
|
||||
['-20', 'string'],
|
||||
['0.01', 'string'],
|
||||
['-0.40', 'string'],
|
||||
[new BcMath\Number('80.3'), 'object'],
|
||||
[new BcMath\Number('-50.6'), 'object'],
|
||||
];
|
||||
|
||||
foreach ($values1 as $value1) {
|
||||
$num = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values2 as [$value2, $type]) {
|
||||
echo "{$value1} + {$value2}: {$type}\n";
|
||||
$ret = $num->add($value2);
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100.012 + 100: int
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(7) "200.012"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 + -30: int
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(6) "70.012"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 + -20: string
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(6) "80.012"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 + 0.01: string
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(7) "100.022"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 + -0.40: string
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(6) "99.612"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 + 80.3: object
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(7) "180.312"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 + -50.6: object
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(6) "49.412"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 + 100: int
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(6) "-0.012"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 + -30: int
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(8) "-130.012"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 + -20: string
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(8) "-120.012"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 + 0.01: string
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(8) "-100.002"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 + -0.40: string
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(8) "-100.412"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 + 80.3: object
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(7) "-19.712"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 + -50.6: object
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(8) "-150.612"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
41
ext/bcmath/tests/number/methods/add_with_scale.phpt
Normal file
41
ext/bcmath/tests/number/methods/add_with_scale.phpt
Normal file
|
@ -0,0 +1,41 @@
|
|||
--TEST--
|
||||
BcMath\Number add() with scale
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$scales = [0, 1, 2, 3, 4];
|
||||
|
||||
$values1 = ['100.012', '-100.012'];
|
||||
|
||||
$values2 = [
|
||||
[100, 'int'],
|
||||
[-30, 'int'],
|
||||
['100.012', 'string'],
|
||||
['-100.012', 'string'],
|
||||
['-20', 'string'],
|
||||
['0.01', 'string'],
|
||||
['-0.40', 'string'],
|
||||
[new BcMath\Number('80.3'), 'object'],
|
||||
[new BcMath\Number('-50.6'), 'object'],
|
||||
];
|
||||
|
||||
foreach ($scales as $scale) {
|
||||
foreach ($values1 as $value1) {
|
||||
$num = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values2 as [$value2, $type]) {
|
||||
$func_ret = bcadd($value1, (string) $value2, $scale);
|
||||
$method_ret = $num->add($value2, $scale);
|
||||
if ($method_ret->compare($func_ret) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
var_dump($value1, $value2, $scale, $func_ret, $method_ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
echo 'done!';
|
||||
?>
|
||||
--EXPECT--
|
||||
done!
|
125
ext/bcmath/tests/number/methods/calc_methods_num_arg_error.phpt
Normal file
125
ext/bcmath/tests/number/methods/calc_methods_num_arg_error.phpt
Normal file
|
@ -0,0 +1,125 @@
|
|||
--TEST--
|
||||
BcMath\Number calc methods (add, sub, mul, div, mod, pow) num arg error
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
$args = [
|
||||
['a', 'non number str'],
|
||||
[[], 'array'],
|
||||
[new stdClass(), 'other object'],
|
||||
[0.1, 'float'],
|
||||
[null, 'null'],
|
||||
];
|
||||
|
||||
$methods = [
|
||||
'add',
|
||||
'sub',
|
||||
'mul',
|
||||
'div',
|
||||
'mod',
|
||||
'pow',
|
||||
];
|
||||
|
||||
$num = new BcMath\Number('100.0000');
|
||||
foreach ($methods as $method) {
|
||||
echo "========== {$method} ==========\n";
|
||||
foreach ($args as [$val, $type]) {
|
||||
echo "{$type}:\n";
|
||||
try {
|
||||
$num->$method($val);
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
}
|
||||
echo "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
========== add ==========
|
||||
non number str:
|
||||
BcMath\Number::add(): Argument #1 ($num) is not well-formed
|
||||
array:
|
||||
BcMath\Number::add(): Argument #1 ($num) must be of type int, string, or BcMath\Number, array given
|
||||
other object:
|
||||
BcMath\Number::add(): Argument #1 ($num) must be of type int, string, or BcMath\Number, stdClass given
|
||||
float:
|
||||
|
||||
Deprecated: Implicit conversion from float 0.1 to int loses precision in %s
|
||||
null:
|
||||
|
||||
Deprecated: BcMath\Number::add(): Passing null to parameter #1 ($num) of type BcMath\Number|string|int is deprecated in %s
|
||||
|
||||
========== sub ==========
|
||||
non number str:
|
||||
BcMath\Number::sub(): Argument #1 ($num) is not well-formed
|
||||
array:
|
||||
BcMath\Number::sub(): Argument #1 ($num) must be of type int, string, or BcMath\Number, array given
|
||||
other object:
|
||||
BcMath\Number::sub(): Argument #1 ($num) must be of type int, string, or BcMath\Number, stdClass given
|
||||
float:
|
||||
|
||||
Deprecated: Implicit conversion from float 0.1 to int loses precision in %s
|
||||
null:
|
||||
|
||||
Deprecated: BcMath\Number::sub(): Passing null to parameter #1 ($num) of type BcMath\Number|string|int is deprecated in %s
|
||||
|
||||
========== mul ==========
|
||||
non number str:
|
||||
BcMath\Number::mul(): Argument #1 ($num) is not well-formed
|
||||
array:
|
||||
BcMath\Number::mul(): Argument #1 ($num) must be of type int, string, or BcMath\Number, array given
|
||||
other object:
|
||||
BcMath\Number::mul(): Argument #1 ($num) must be of type int, string, or BcMath\Number, stdClass given
|
||||
float:
|
||||
|
||||
Deprecated: Implicit conversion from float 0.1 to int loses precision in %s
|
||||
null:
|
||||
|
||||
Deprecated: BcMath\Number::mul(): Passing null to parameter #1 ($num) of type BcMath\Number|string|int is deprecated in %s
|
||||
|
||||
========== div ==========
|
||||
non number str:
|
||||
BcMath\Number::div(): Argument #1 ($num) is not well-formed
|
||||
array:
|
||||
BcMath\Number::div(): Argument #1 ($num) must be of type int, string, or BcMath\Number, array given
|
||||
other object:
|
||||
BcMath\Number::div(): Argument #1 ($num) must be of type int, string, or BcMath\Number, stdClass given
|
||||
float:
|
||||
|
||||
Deprecated: Implicit conversion from float 0.1 to int loses precision in %s
|
||||
Division by zero
|
||||
null:
|
||||
|
||||
Deprecated: BcMath\Number::div(): Passing null to parameter #1 ($num) of type BcMath\Number|string|int is deprecated in %s
|
||||
Division by zero
|
||||
|
||||
========== mod ==========
|
||||
non number str:
|
||||
BcMath\Number::mod(): Argument #1 ($num) is not well-formed
|
||||
array:
|
||||
BcMath\Number::mod(): Argument #1 ($num) must be of type int, string, or BcMath\Number, array given
|
||||
other object:
|
||||
BcMath\Number::mod(): Argument #1 ($num) must be of type int, string, or BcMath\Number, stdClass given
|
||||
float:
|
||||
|
||||
Deprecated: Implicit conversion from float 0.1 to int loses precision in %s
|
||||
Modulo by zero
|
||||
null:
|
||||
|
||||
Deprecated: BcMath\Number::mod(): Passing null to parameter #1 ($num) of type BcMath\Number|string|int is deprecated in %s
|
||||
Modulo by zero
|
||||
|
||||
========== pow ==========
|
||||
non number str:
|
||||
BcMath\Number::pow(): Argument #1 ($exponent) is not well-formed
|
||||
array:
|
||||
BcMath\Number::pow(): Argument #1 ($exponent) must be of type int, string, or BcMath\Number, array given
|
||||
other object:
|
||||
BcMath\Number::pow(): Argument #1 ($exponent) must be of type int, string, or BcMath\Number, stdClass given
|
||||
float:
|
||||
|
||||
Deprecated: Implicit conversion from float 0.1 to int loses precision in %s
|
||||
null:
|
||||
|
||||
Deprecated: BcMath\Number::pow(): Passing null to parameter #1 ($exponent) of type BcMath\Number|string|int is deprecated in %s
|
|
@ -0,0 +1,89 @@
|
|||
--TEST--
|
||||
BcMath\Number calc methods (add, sub, mul, div, mod, pow) scale arg error
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
$args = [
|
||||
[[], 'array'],
|
||||
[new stdClass(), 'other object'],
|
||||
[0.1, 'float'],
|
||||
];
|
||||
|
||||
$methods = [
|
||||
'add',
|
||||
'sub',
|
||||
'mul',
|
||||
'div',
|
||||
'mod',
|
||||
'pow',
|
||||
];
|
||||
|
||||
$num = new BcMath\Number('100.0000');
|
||||
foreach ($methods as $method) {
|
||||
echo "========== {$method} ==========\n";
|
||||
foreach ($args as [$val, $type]) {
|
||||
echo "{$type}:\n";
|
||||
try {
|
||||
$num->$method(1, $val);
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
}
|
||||
echo "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
========== add ==========
|
||||
array:
|
||||
BcMath\Number::add(): Argument #2 ($scale) must be of type ?int, array given
|
||||
other object:
|
||||
BcMath\Number::add(): Argument #2 ($scale) must be of type ?int, stdClass given
|
||||
float:
|
||||
|
||||
Deprecated: Implicit conversion from float 0.1 to int loses precision in %s
|
||||
|
||||
========== sub ==========
|
||||
array:
|
||||
BcMath\Number::sub(): Argument #2 ($scale) must be of type ?int, array given
|
||||
other object:
|
||||
BcMath\Number::sub(): Argument #2 ($scale) must be of type ?int, stdClass given
|
||||
float:
|
||||
|
||||
Deprecated: Implicit conversion from float 0.1 to int loses precision in %s
|
||||
|
||||
========== mul ==========
|
||||
array:
|
||||
BcMath\Number::mul(): Argument #2 ($scale) must be of type ?int, array given
|
||||
other object:
|
||||
BcMath\Number::mul(): Argument #2 ($scale) must be of type ?int, stdClass given
|
||||
float:
|
||||
|
||||
Deprecated: Implicit conversion from float 0.1 to int loses precision in %s
|
||||
|
||||
========== div ==========
|
||||
array:
|
||||
BcMath\Number::div(): Argument #2 ($scale) must be of type ?int, array given
|
||||
other object:
|
||||
BcMath\Number::div(): Argument #2 ($scale) must be of type ?int, stdClass given
|
||||
float:
|
||||
|
||||
Deprecated: Implicit conversion from float 0.1 to int loses precision in %s
|
||||
|
||||
========== mod ==========
|
||||
array:
|
||||
BcMath\Number::mod(): Argument #2 ($scale) must be of type ?int, array given
|
||||
other object:
|
||||
BcMath\Number::mod(): Argument #2 ($scale) must be of type ?int, stdClass given
|
||||
float:
|
||||
|
||||
Deprecated: Implicit conversion from float 0.1 to int loses precision in %s
|
||||
|
||||
========== pow ==========
|
||||
array:
|
||||
BcMath\Number::pow(): Argument #2 ($scale) must be of type ?int, array given
|
||||
other object:
|
||||
BcMath\Number::pow(): Argument #2 ($scale) must be of type ?int, stdClass given
|
||||
float:
|
||||
|
||||
Deprecated: Implicit conversion from float 0.1 to int loses precision in %s
|
37
ext/bcmath/tests/number/methods/ceil.phpt
Normal file
37
ext/bcmath/tests/number/methods/ceil.phpt
Normal file
|
@ -0,0 +1,37 @@
|
|||
--TEST--
|
||||
BcMath\Number ceil()
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
$nums = [
|
||||
'0',
|
||||
'0.00',
|
||||
'-0',
|
||||
'-0.00',
|
||||
'0.01',
|
||||
'0.000000000000000000000000000000000000000001',
|
||||
'-0.01',
|
||||
'-0.000000000000000000000000000000000000000001',
|
||||
'1',
|
||||
'1.0000',
|
||||
'1.0001',
|
||||
'100000.000000000000000000000000000000000000000001',
|
||||
'-1',
|
||||
'-1.0000',
|
||||
'-1.0001',
|
||||
'-100000.000000000000000000000000000000000000000001',
|
||||
];
|
||||
|
||||
foreach ($nums as $num) {
|
||||
$func_ret = bcceil($num);
|
||||
$method_ret = (new BcMath\Number($num))->ceil();
|
||||
if ($method_ret->compare($func_ret, 0) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
var_dump($num, $func_ret, $method_ret);
|
||||
}
|
||||
}
|
||||
echo 'done!';
|
||||
?>
|
||||
--EXPECT--
|
||||
done!
|
63
ext/bcmath/tests/number/methods/compare.phpt
Normal file
63
ext/bcmath/tests/number/methods/compare.phpt
Normal file
|
@ -0,0 +1,63 @@
|
|||
--TEST--
|
||||
BcMath\Number compare()
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values2 = [
|
||||
[99, 'int'],
|
||||
['99.9999', 'string'],
|
||||
[new BcMath\Number('99.9999'), 'object'],
|
||||
[100, 'int'],
|
||||
['100', 'string'],
|
||||
['100.0000', 'string'],
|
||||
[new BcMath\Number(100), 'object'],
|
||||
[new BcMath\Number('100.0000'), 'object'],
|
||||
[101, 'int'],
|
||||
['100.00001', 'string'],
|
||||
[new BcMath\Number('100.00001'), 'object'],
|
||||
];
|
||||
|
||||
$value1 = new BcMath\Number('100.0000');
|
||||
|
||||
foreach ($values2 as [$value2, $type2]) {
|
||||
echo "========== with {$type2} {$value2} ==========\n";
|
||||
var_dump($value1->compare($value2));
|
||||
|
||||
echo "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
========== with int 99 ==========
|
||||
int(1)
|
||||
|
||||
========== with string 99.9999 ==========
|
||||
int(1)
|
||||
|
||||
========== with object 99.9999 ==========
|
||||
int(1)
|
||||
|
||||
========== with int 100 ==========
|
||||
int(0)
|
||||
|
||||
========== with string 100 ==========
|
||||
int(0)
|
||||
|
||||
========== with string 100.0000 ==========
|
||||
int(0)
|
||||
|
||||
========== with object 100 ==========
|
||||
int(0)
|
||||
|
||||
========== with object 100.0000 ==========
|
||||
int(0)
|
||||
|
||||
========== with int 101 ==========
|
||||
int(-1)
|
||||
|
||||
========== with string 100.00001 ==========
|
||||
int(-1)
|
||||
|
||||
========== with object 100.00001 ==========
|
||||
int(-1)
|
42
ext/bcmath/tests/number/methods/compare_arg_error.phpt
Normal file
42
ext/bcmath/tests/number/methods/compare_arg_error.phpt
Normal file
|
@ -0,0 +1,42 @@
|
|||
--TEST--
|
||||
BcMath\Number compare() arg error
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
$args = [
|
||||
['a', 'non number str'],
|
||||
[[], 'array'],
|
||||
[new stdClass(), 'other object'],
|
||||
[0.1, 'float'],
|
||||
[null, 'null'],
|
||||
];
|
||||
|
||||
$num = new BcMath\Number('100.0000');
|
||||
foreach ($args as [$val, $type]) {
|
||||
echo "{$type}:\n";
|
||||
try {
|
||||
$num->compare($val);
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
echo "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
non number str:
|
||||
BcMath\Number::compare(): Argument #1 ($num) is not well-formed
|
||||
|
||||
array:
|
||||
BcMath\Number::compare(): Argument #1 ($num) must be of type int, string, or BcMath\Number, array given
|
||||
|
||||
other object:
|
||||
BcMath\Number::compare(): Argument #1 ($num) must be of type int, string, or BcMath\Number, stdClass given
|
||||
|
||||
float:
|
||||
|
||||
Deprecated: Implicit conversion from float 0.1 to int loses precision in %s
|
||||
|
||||
null:
|
||||
|
||||
Deprecated: BcMath\Number::compare(): Passing null to parameter #1 ($num) of type BcMath\Number|string|int is deprecated in %s
|
239
ext/bcmath/tests/number/methods/compare_with_scale.phpt
Normal file
239
ext/bcmath/tests/number/methods/compare_with_scale.phpt
Normal file
|
@ -0,0 +1,239 @@
|
|||
--TEST--
|
||||
BcMath\Number compare() with scale
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values2 = [
|
||||
[100, 'int'],
|
||||
['100.0000', 'string'],
|
||||
[new BcMath\Number('100.0000'), 'object'],
|
||||
['100.0001', 'string'],
|
||||
[new BcMath\Number('100.0001'), 'object'],
|
||||
['100.0010', 'string'],
|
||||
[new BcMath\Number('100.0010'), 'object'],
|
||||
['100.0100', 'string'],
|
||||
[new BcMath\Number('100.0100'), 'object'],
|
||||
['100.0011', 'string'],
|
||||
[new BcMath\Number('100.0011'), 'object'],
|
||||
];
|
||||
|
||||
$value1 = new BcMath\Number('100.0011');
|
||||
|
||||
$scales = [0, 1, 2, 3, 4, 5];
|
||||
|
||||
foreach ($scales as $scale) {
|
||||
echo "========== scale is {$scale} ==========\n";
|
||||
foreach ($values2 as [$value2, $type2]) {
|
||||
echo "with {$type2} {$value2}:\n";
|
||||
var_dump($value1->compare($value2, $scale));
|
||||
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
========== scale is 0 ==========
|
||||
with int 100:
|
||||
int(0)
|
||||
|
||||
with string 100.0000:
|
||||
int(0)
|
||||
|
||||
with object 100.0000:
|
||||
int(0)
|
||||
|
||||
with string 100.0001:
|
||||
int(0)
|
||||
|
||||
with object 100.0001:
|
||||
int(0)
|
||||
|
||||
with string 100.0010:
|
||||
int(0)
|
||||
|
||||
with object 100.0010:
|
||||
int(0)
|
||||
|
||||
with string 100.0100:
|
||||
int(0)
|
||||
|
||||
with object 100.0100:
|
||||
int(0)
|
||||
|
||||
with string 100.0011:
|
||||
int(0)
|
||||
|
||||
with object 100.0011:
|
||||
int(0)
|
||||
|
||||
========== scale is 1 ==========
|
||||
with int 100:
|
||||
int(0)
|
||||
|
||||
with string 100.0000:
|
||||
int(0)
|
||||
|
||||
with object 100.0000:
|
||||
int(0)
|
||||
|
||||
with string 100.0001:
|
||||
int(0)
|
||||
|
||||
with object 100.0001:
|
||||
int(0)
|
||||
|
||||
with string 100.0010:
|
||||
int(0)
|
||||
|
||||
with object 100.0010:
|
||||
int(0)
|
||||
|
||||
with string 100.0100:
|
||||
int(0)
|
||||
|
||||
with object 100.0100:
|
||||
int(0)
|
||||
|
||||
with string 100.0011:
|
||||
int(0)
|
||||
|
||||
with object 100.0011:
|
||||
int(0)
|
||||
|
||||
========== scale is 2 ==========
|
||||
with int 100:
|
||||
int(0)
|
||||
|
||||
with string 100.0000:
|
||||
int(0)
|
||||
|
||||
with object 100.0000:
|
||||
int(0)
|
||||
|
||||
with string 100.0001:
|
||||
int(0)
|
||||
|
||||
with object 100.0001:
|
||||
int(0)
|
||||
|
||||
with string 100.0010:
|
||||
int(0)
|
||||
|
||||
with object 100.0010:
|
||||
int(0)
|
||||
|
||||
with string 100.0100:
|
||||
int(-1)
|
||||
|
||||
with object 100.0100:
|
||||
int(-1)
|
||||
|
||||
with string 100.0011:
|
||||
int(0)
|
||||
|
||||
with object 100.0011:
|
||||
int(0)
|
||||
|
||||
========== scale is 3 ==========
|
||||
with int 100:
|
||||
int(1)
|
||||
|
||||
with string 100.0000:
|
||||
int(1)
|
||||
|
||||
with object 100.0000:
|
||||
int(1)
|
||||
|
||||
with string 100.0001:
|
||||
int(1)
|
||||
|
||||
with object 100.0001:
|
||||
int(1)
|
||||
|
||||
with string 100.0010:
|
||||
int(0)
|
||||
|
||||
with object 100.0010:
|
||||
int(0)
|
||||
|
||||
with string 100.0100:
|
||||
int(-1)
|
||||
|
||||
with object 100.0100:
|
||||
int(-1)
|
||||
|
||||
with string 100.0011:
|
||||
int(0)
|
||||
|
||||
with object 100.0011:
|
||||
int(0)
|
||||
|
||||
========== scale is 4 ==========
|
||||
with int 100:
|
||||
int(1)
|
||||
|
||||
with string 100.0000:
|
||||
int(1)
|
||||
|
||||
with object 100.0000:
|
||||
int(1)
|
||||
|
||||
with string 100.0001:
|
||||
int(1)
|
||||
|
||||
with object 100.0001:
|
||||
int(1)
|
||||
|
||||
with string 100.0010:
|
||||
int(1)
|
||||
|
||||
with object 100.0010:
|
||||
int(1)
|
||||
|
||||
with string 100.0100:
|
||||
int(-1)
|
||||
|
||||
with object 100.0100:
|
||||
int(-1)
|
||||
|
||||
with string 100.0011:
|
||||
int(0)
|
||||
|
||||
with object 100.0011:
|
||||
int(0)
|
||||
|
||||
========== scale is 5 ==========
|
||||
with int 100:
|
||||
int(1)
|
||||
|
||||
with string 100.0000:
|
||||
int(1)
|
||||
|
||||
with object 100.0000:
|
||||
int(1)
|
||||
|
||||
with string 100.0001:
|
||||
int(1)
|
||||
|
||||
with object 100.0001:
|
||||
int(1)
|
||||
|
||||
with string 100.0010:
|
||||
int(1)
|
||||
|
||||
with object 100.0010:
|
||||
int(1)
|
||||
|
||||
with string 100.0100:
|
||||
int(-1)
|
||||
|
||||
with object 100.0100:
|
||||
int(-1)
|
||||
|
||||
with string 100.0011:
|
||||
int(0)
|
||||
|
||||
with object 100.0011:
|
||||
int(0)
|
142
ext/bcmath/tests/number/methods/div.phpt
Normal file
142
ext/bcmath/tests/number/methods/div.phpt
Normal file
|
@ -0,0 +1,142 @@
|
|||
--TEST--
|
||||
BcMath\Number div()
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values1 = ['100.012', '-100.012'];
|
||||
|
||||
$values2 = [
|
||||
[100, 'int'],
|
||||
[-30, 'int'],
|
||||
['-20', 'string'],
|
||||
['0.01', 'string'],
|
||||
['-0.40', 'string'],
|
||||
[new BcMath\Number('80.3'), 'object'],
|
||||
[new BcMath\Number('-50.6'), 'object'],
|
||||
];
|
||||
|
||||
foreach ($values1 as $value1) {
|
||||
$num = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values2 as [$value2, $type]) {
|
||||
echo "{$value1} / {$value2}: {$type}\n";
|
||||
$ret = $num->div($value2);
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100.012 / 100: int
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(7) "1.00012"
|
||||
["scale"]=>
|
||||
int(5)
|
||||
}
|
||||
|
||||
100.012 / -30: int
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(16) "-3.3337333333333"
|
||||
["scale"]=>
|
||||
int(13)
|
||||
}
|
||||
|
||||
100.012 / -20: string
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(7) "-5.0006"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
100.012 / 0.01: string
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(9) "10001.200"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 / -0.40: string
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(8) "-250.030"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 / 80.3: object
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(15) "1.2454794520547"
|
||||
["scale"]=>
|
||||
int(13)
|
||||
}
|
||||
|
||||
100.012 / -50.6: object
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(16) "-1.9765217391304"
|
||||
["scale"]=>
|
||||
int(13)
|
||||
}
|
||||
|
||||
-100.012 / 100: int
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(8) "-1.00012"
|
||||
["scale"]=>
|
||||
int(5)
|
||||
}
|
||||
|
||||
-100.012 / -30: int
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(15) "3.3337333333333"
|
||||
["scale"]=>
|
||||
int(13)
|
||||
}
|
||||
|
||||
-100.012 / -20: string
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(6) "5.0006"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
-100.012 / 0.01: string
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(10) "-10001.200"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 / -0.40: string
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(7) "250.030"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 / 80.3: object
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(16) "-1.2454794520547"
|
||||
["scale"]=>
|
||||
int(13)
|
||||
}
|
||||
|
||||
-100.012 / -50.6: object
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(15) "1.9765217391304"
|
||||
["scale"]=>
|
||||
int(13)
|
||||
}
|
39
ext/bcmath/tests/number/methods/div_with_scale.phpt
Normal file
39
ext/bcmath/tests/number/methods/div_with_scale.phpt
Normal file
|
@ -0,0 +1,39 @@
|
|||
--TEST--
|
||||
BcMath\Number div() with scale
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$scales = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
|
||||
$values1 = ['100.012', '-100.012'];
|
||||
|
||||
$values2 = [
|
||||
[100, 'int'],
|
||||
[-30, 'int'],
|
||||
['-20', 'string'],
|
||||
['0.01', 'string'],
|
||||
['-0.40', 'string'],
|
||||
[new BcMath\Number('80.3'), 'object'],
|
||||
[new BcMath\Number('-50.6'), 'object'],
|
||||
];
|
||||
|
||||
foreach ($scales as $scale) {
|
||||
foreach ($values1 as $value1) {
|
||||
$num = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values2 as [$value2, $type]) {
|
||||
$func_ret = bcdiv($value1, (string) $value2, $scale);
|
||||
$method_ret = $num->div($value2, $scale);
|
||||
if ($method_ret->compare($func_ret) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
var_dump($value1, $value2, $scale, $func_ret, $method_ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
echo 'done!';
|
||||
?>
|
||||
--EXPECT--
|
||||
done!
|
37
ext/bcmath/tests/number/methods/floor.phpt
Normal file
37
ext/bcmath/tests/number/methods/floor.phpt
Normal file
|
@ -0,0 +1,37 @@
|
|||
--TEST--
|
||||
BcMath\Number floor()
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
$nums = [
|
||||
'0',
|
||||
'0.00',
|
||||
'-0',
|
||||
'-0.00',
|
||||
'0.01',
|
||||
'0.000000000000000000000000000000000000000001',
|
||||
'-0.01',
|
||||
'-0.000000000000000000000000000000000000000001',
|
||||
'1',
|
||||
'1.0000',
|
||||
'1.0001',
|
||||
'100000.000000000000000000000000000000000000000001',
|
||||
'-1',
|
||||
'-1.0000',
|
||||
'-1.0001',
|
||||
'-100000.000000000000000000000000000000000000000001',
|
||||
];
|
||||
|
||||
foreach ($nums as $num) {
|
||||
$func_ret = bcfloor($num);
|
||||
$method_ret = (new BcMath\Number($num))->floor();
|
||||
if ($method_ret->compare($func_ret) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
var_dump($num, $func_ret, $method_ret);
|
||||
}
|
||||
}
|
||||
echo 'done!';
|
||||
?>
|
||||
--EXPECT--
|
||||
done!
|
142
ext/bcmath/tests/number/methods/mod.phpt
Normal file
142
ext/bcmath/tests/number/methods/mod.phpt
Normal file
|
@ -0,0 +1,142 @@
|
|||
--TEST--
|
||||
BcMath\Number mod()
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values1 = ['100.012', '-100.012'];
|
||||
|
||||
$values2 = [
|
||||
[100, 'int'],
|
||||
[-30, 'int'],
|
||||
['-20', 'string'],
|
||||
['0.01', 'string'],
|
||||
['-0.40', 'string'],
|
||||
[new BcMath\Number('80.3'), 'object'],
|
||||
[new BcMath\Number('-50.6'), 'object'],
|
||||
];
|
||||
|
||||
foreach ($values1 as $value1) {
|
||||
$num = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values2 as [$value2, $type]) {
|
||||
echo "{$value1} % {$value2}: {$type}\n";
|
||||
$ret = $num->mod($value2);
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100.012 % 100: int
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(5) "0.012"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 % -30: int
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(6) "10.012"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 % -20: string
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(5) "0.012"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 % 0.01: string
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(5) "0.002"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 % -0.40: string
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(5) "0.012"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 % 80.3: object
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(6) "19.712"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 % -50.6: object
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(6) "49.412"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 % 100: int
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(6) "-0.012"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 % -30: int
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(7) "-10.012"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 % -20: string
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(6) "-0.012"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 % 0.01: string
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(6) "-0.002"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 % -0.40: string
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(6) "-0.012"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 % 80.3: object
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(7) "-19.712"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 % -50.6: object
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(7) "-49.412"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
39
ext/bcmath/tests/number/methods/mod_with_scale.phpt
Normal file
39
ext/bcmath/tests/number/methods/mod_with_scale.phpt
Normal file
|
@ -0,0 +1,39 @@
|
|||
--TEST--
|
||||
BcMath\Number mod() with scale
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$scales = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
|
||||
$values1 = ['100.012', '-100.012'];
|
||||
|
||||
$values2 = [
|
||||
[100, 'int'],
|
||||
[-30, 'int'],
|
||||
['-20', 'string'],
|
||||
['0.01', 'string'],
|
||||
['-0.40', 'string'],
|
||||
[new BcMath\Number('80.3'), 'object'],
|
||||
[new BcMath\Number('-50.6'), 'object'],
|
||||
];
|
||||
|
||||
foreach ($scales as $scale) {
|
||||
foreach ($values1 as $value1) {
|
||||
$num = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values2 as [$value2, $type]) {
|
||||
$func_ret = bcmod($value1, (string) $value2, $scale);
|
||||
$method_ret = $num->mod($value2, $scale);
|
||||
if ($method_ret->compare($func_ret) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
var_dump($value1, $value2, $scale, $func_ret, $method_ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
echo 'done!';
|
||||
?>
|
||||
--EXPECT--
|
||||
done!
|
142
ext/bcmath/tests/number/methods/mul.phpt
Normal file
142
ext/bcmath/tests/number/methods/mul.phpt
Normal file
|
@ -0,0 +1,142 @@
|
|||
--TEST--
|
||||
BcMath\Number mul()
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values1 = ['100.012', '-100.012'];
|
||||
|
||||
$values2 = [
|
||||
[100, 'int'],
|
||||
[-30, 'int'],
|
||||
['-20', 'string'],
|
||||
['0.01', 'string'],
|
||||
['-0.40', 'string'],
|
||||
[new BcMath\Number('80.3'), 'object'],
|
||||
[new BcMath\Number('-50.6'), 'object'],
|
||||
];
|
||||
|
||||
foreach ($values1 as $value1) {
|
||||
$num = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values2 as [$value2, $type]) {
|
||||
echo "{$value1} * {$value2}: {$type}\n";
|
||||
$ret = $num->mul($value2);
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100.012 * 100: int
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(9) "10001.200"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 * -30: int
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(9) "-3000.360"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 * -20: string
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(9) "-2000.240"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 * 0.01: string
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(7) "1.00012"
|
||||
["scale"]=>
|
||||
int(5)
|
||||
}
|
||||
|
||||
100.012 * -0.40: string
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(9) "-40.00480"
|
||||
["scale"]=>
|
||||
int(5)
|
||||
}
|
||||
|
||||
100.012 * 80.3: object
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(9) "8030.9636"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
100.012 * -50.6: object
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(10) "-5060.6072"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
-100.012 * 100: int
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(10) "-10001.200"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 * -30: int
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(8) "3000.360"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 * -20: string
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(8) "2000.240"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 * 0.01: string
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(8) "-1.00012"
|
||||
["scale"]=>
|
||||
int(5)
|
||||
}
|
||||
|
||||
-100.012 * -0.40: string
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(8) "40.00480"
|
||||
["scale"]=>
|
||||
int(5)
|
||||
}
|
||||
|
||||
-100.012 * 80.3: object
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(10) "-8030.9636"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
-100.012 * -50.6: object
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(9) "5060.6072"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
39
ext/bcmath/tests/number/methods/mul_with_scale.phpt
Normal file
39
ext/bcmath/tests/number/methods/mul_with_scale.phpt
Normal file
|
@ -0,0 +1,39 @@
|
|||
--TEST--
|
||||
BcMath\Number mul() with scale
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$scales = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
|
||||
$values1 = ['100.012', '-100.012'];
|
||||
|
||||
$values2 = [
|
||||
[100, 'int'],
|
||||
[-30, 'int'],
|
||||
['-20', 'string'],
|
||||
['0.01', 'string'],
|
||||
['-0.40', 'string'],
|
||||
[new BcMath\Number('80.3'), 'object'],
|
||||
[new BcMath\Number('-50.6'), 'object'],
|
||||
];
|
||||
|
||||
foreach ($scales as $scale) {
|
||||
foreach ($values1 as $value1) {
|
||||
$num = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values2 as [$value2, $type]) {
|
||||
$func_ret = bcmul($value1, (string) $value2, $scale);
|
||||
$method_ret = $num->mul($value2, $scale);
|
||||
if ($method_ret->compare($func_ret) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
var_dump($value1, $value2, $scale, $func_ret, $method_ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
echo 'done!';
|
||||
?>
|
||||
--EXPECT--
|
||||
done!
|
142
ext/bcmath/tests/number/methods/pow.phpt
Normal file
142
ext/bcmath/tests/number/methods/pow.phpt
Normal file
|
@ -0,0 +1,142 @@
|
|||
--TEST--
|
||||
BcMath\Number pow()
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = ['12.5', '-12.5'];
|
||||
|
||||
$exponents = [
|
||||
[2, 'int'],
|
||||
[-3, 'int'],
|
||||
['-2', 'string'],
|
||||
['0', 'string'],
|
||||
[new BcMath\Number('2'), 'object'],
|
||||
[new BcMath\Number('-2'), 'object'],
|
||||
[new BcMath\Number('0'), 'object'],
|
||||
];
|
||||
|
||||
foreach ($values as $value) {
|
||||
$num = new BcMath\Number($value);
|
||||
|
||||
foreach ($exponents as [$exponent, $type]) {
|
||||
echo "{$value} ** {$exponent}: {$type}\n";
|
||||
$ret = $num->pow($exponent);
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
12.5 ** 2: int
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(6) "156.25"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
12.5 ** -3: int
|
||||
object(BcMath\Number)#6 (2) {
|
||||
["value"]=>
|
||||
string(8) "0.000512"
|
||||
["scale"]=>
|
||||
int(6)
|
||||
}
|
||||
|
||||
12.5 ** -2: string
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.0064"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
12.5 ** 0: string
|
||||
object(BcMath\Number)#6 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
12.5 ** 2: object
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(6) "156.25"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
12.5 ** -2: object
|
||||
object(BcMath\Number)#6 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.0064"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
12.5 ** 0: object
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-12.5 ** 2: int
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(6) "156.25"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-12.5 ** -3: int
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(9) "-0.000512"
|
||||
["scale"]=>
|
||||
int(6)
|
||||
}
|
||||
|
||||
-12.5 ** -2: string
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.0064"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
-12.5 ** 0: string
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-12.5 ** 2: object
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(6) "156.25"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-12.5 ** -2: object
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.0064"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
-12.5 ** 0: object
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
39
ext/bcmath/tests/number/methods/pow_with_scale.phpt
Normal file
39
ext/bcmath/tests/number/methods/pow_with_scale.phpt
Normal file
|
@ -0,0 +1,39 @@
|
|||
--TEST--
|
||||
BcMath\Number pow() with scale
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$scales = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
|
||||
$values = ['12.5', '-12.5'];
|
||||
|
||||
$exponents = [
|
||||
[2, 'int'],
|
||||
[-3, 'int'],
|
||||
['-2', 'string'],
|
||||
['0', 'string'],
|
||||
[new BcMath\Number('2'), 'object'],
|
||||
[new BcMath\Number('-2'), 'object'],
|
||||
[new BcMath\Number('0'), 'object'],
|
||||
];
|
||||
|
||||
foreach ($scales as $scale) {
|
||||
foreach ($values as $value) {
|
||||
$num = new BcMath\Number($value);
|
||||
|
||||
foreach ($exponents as [$exponent, $type]) {
|
||||
$func_ret = bcpow($value, (string) $exponent, $scale);
|
||||
$method_ret = $num->pow($exponent, $scale);
|
||||
if ($method_ret->compare($func_ret) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
var_dump($value, $exponent, $scale, $func_ret, $method_ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
echo 'done!';
|
||||
?>
|
||||
--EXPECT--
|
||||
done!
|
276
ext/bcmath/tests/number/methods/powmod.phpt
Normal file
276
ext/bcmath/tests/number/methods/powmod.phpt
Normal file
|
@ -0,0 +1,276 @@
|
|||
--TEST--
|
||||
BcMath\Number powmod()
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = ['12', '-12'];
|
||||
|
||||
$exponents = [
|
||||
[2, 'int'],
|
||||
['0', 'string'],
|
||||
['3', 'string'],
|
||||
[new BcMath\Number('2'), 'object'],
|
||||
[new BcMath\Number('0'), 'object'],
|
||||
];
|
||||
|
||||
$mods = [
|
||||
[2, 'int'],
|
||||
['3', 'string'],
|
||||
[new BcMath\Number('2'), 'object'],
|
||||
];
|
||||
|
||||
foreach ($values as $value) {
|
||||
$num = new BcMath\Number($value);
|
||||
|
||||
foreach ($exponents as [$exponent, $type_ex]) {
|
||||
foreach ($mods as [$mod, $type_mod]) {
|
||||
echo "{$value}, expo is {$exponent}({$type_ex}), mod is {$mod}({$type_mod}):\n";
|
||||
$ret = $num->powmod($exponent, $mod);
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
12, expo is 2(int), mod is 2(int):
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
12, expo is 2(int), mod is 3(string):
|
||||
object(BcMath\Number)#6 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
12, expo is 2(int), mod is 2(object):
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
12, expo is 0(string), mod is 2(int):
|
||||
object(BcMath\Number)#6 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
12, expo is 0(string), mod is 3(string):
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
12, expo is 0(string), mod is 2(object):
|
||||
object(BcMath\Number)#6 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
12, expo is 3(string), mod is 2(int):
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
12, expo is 3(string), mod is 3(string):
|
||||
object(BcMath\Number)#6 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
12, expo is 3(string), mod is 2(object):
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
12, expo is 2(object), mod is 2(int):
|
||||
object(BcMath\Number)#6 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
12, expo is 2(object), mod is 3(string):
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
12, expo is 2(object), mod is 2(object):
|
||||
object(BcMath\Number)#6 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
12, expo is 0(object), mod is 2(int):
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
12, expo is 0(object), mod is 3(string):
|
||||
object(BcMath\Number)#6 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
12, expo is 0(object), mod is 2(object):
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-12, expo is 2(int), mod is 2(int):
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-12, expo is 2(int), mod is 3(string):
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-12, expo is 2(int), mod is 2(object):
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-12, expo is 0(string), mod is 2(int):
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-12, expo is 0(string), mod is 3(string):
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-12, expo is 0(string), mod is 2(object):
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-12, expo is 3(string), mod is 2(int):
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-12, expo is 3(string), mod is 3(string):
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-12, expo is 3(string), mod is 2(object):
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-12, expo is 2(object), mod is 2(int):
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-12, expo is 2(object), mod is 3(string):
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-12, expo is 2(object), mod is 2(object):
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-12, expo is 0(object), mod is 2(int):
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-12, expo is 0(object), mod is 3(string):
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-12, expo is 0(object), mod is 2(object):
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
68
ext/bcmath/tests/number/methods/powmod_arg_error.phpt
Normal file
68
ext/bcmath/tests/number/methods/powmod_arg_error.phpt
Normal file
|
@ -0,0 +1,68 @@
|
|||
--TEST--
|
||||
BcMath\Number powmod arg error
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
$args = [
|
||||
['a', 'non number str'],
|
||||
[[], 'array'],
|
||||
[new stdClass(), 'other object'],
|
||||
[0.1, 'float'],
|
||||
[null, 'null'],
|
||||
];
|
||||
|
||||
$num = new BcMath\Number('100.0000');
|
||||
|
||||
echo "========== check 1st arg ==========\n";
|
||||
foreach ($args as [$val, $type]) {
|
||||
echo "{$type}:\n";
|
||||
try {
|
||||
$num->powmod($val, 1);
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
|
||||
echo "========== check 2nd arg ==========\n";
|
||||
foreach ($args as [$val, $type]) {
|
||||
echo "{$type}:\n";
|
||||
try {
|
||||
$num->powmod(1, $val);
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
========== check 1st arg ==========
|
||||
non number str:
|
||||
BcMath\Number::powmod(): Argument #1 ($exponent) is not well-formed
|
||||
array:
|
||||
BcMath\Number::powmod(): Argument #1 ($exponent) must be of type int, string, or BcMath\Number, array given
|
||||
other object:
|
||||
BcMath\Number::powmod(): Argument #1 ($exponent) must be of type int, string, or BcMath\Number, stdClass given
|
||||
float:
|
||||
|
||||
Deprecated: Implicit conversion from float 0.1 to int loses precision in %s
|
||||
null:
|
||||
|
||||
Deprecated: BcMath\Number::powmod(): Passing null to parameter #1 ($exponent) of type BcMath\Number|string|int is deprecated in %s
|
||||
|
||||
========== check 2nd arg ==========
|
||||
non number str:
|
||||
BcMath\Number::powmod(): Argument #2 ($modulus) is not well-formed
|
||||
array:
|
||||
BcMath\Number::powmod(): Argument #2 ($modulus) must be of type int, string, or BcMath\Number, array given
|
||||
other object:
|
||||
BcMath\Number::powmod(): Argument #2 ($modulus) must be of type int, string, or BcMath\Number, stdClass given
|
||||
float:
|
||||
|
||||
Deprecated: Implicit conversion from float 0.1 to int loses precision in %s
|
||||
Modulo by zero
|
||||
null:
|
||||
|
||||
Deprecated: BcMath\Number::powmod(): Passing null to parameter #2 ($modulus) of type BcMath\Number|string|int is deprecated in %s
|
||||
Modulo by zero
|
45
ext/bcmath/tests/number/methods/powmod_with_scale.phpt
Normal file
45
ext/bcmath/tests/number/methods/powmod_with_scale.phpt
Normal file
|
@ -0,0 +1,45 @@
|
|||
--TEST--
|
||||
BcMath\Number powmod() with scale
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$scales = [0, 10];
|
||||
|
||||
$values = ['12', '-12'];
|
||||
|
||||
$exponents = [
|
||||
[2, 'int'],
|
||||
['0', 'string'],
|
||||
['3', 'string'],
|
||||
[new BcMath\Number('2'), 'object'],
|
||||
[new BcMath\Number('0'), 'object'],
|
||||
];
|
||||
|
||||
$mods = [
|
||||
[2, 'int'],
|
||||
['3', 'string'],
|
||||
[new BcMath\Number('2'), 'object'],
|
||||
];
|
||||
|
||||
foreach ($scales as $scale) {
|
||||
foreach ($values as $value) {
|
||||
$num = new BcMath\Number($value);
|
||||
|
||||
foreach ($exponents as [$exponent, $type_ex]) {
|
||||
foreach ($mods as [$mod, $type_mod]) {
|
||||
$func_ret = bcpowmod($value, (string) $exponent, (string) $mod, $scale);
|
||||
$method_ret = $num->powmod($exponent, $mod, $scale);
|
||||
if ($method_ret->compare($func_ret) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
var_dump($value, $exponent, $mod, $scale, $func_ret, $method_ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
echo 'done!';
|
||||
?>
|
||||
--EXPECT--
|
||||
done!
|
48
ext/bcmath/tests/number/methods/round.phpt
Normal file
48
ext/bcmath/tests/number/methods/round.phpt
Normal file
|
@ -0,0 +1,48 @@
|
|||
--TEST--
|
||||
BcMath\Number round()
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
foreach (RoundingMode::cases() as $mode) {
|
||||
foreach ([
|
||||
'0.1',
|
||||
'-0.1',
|
||||
'1.0',
|
||||
'-1.0',
|
||||
'1.2',
|
||||
'-1.2',
|
||||
'1.7',
|
||||
'-1.7',
|
||||
'1.5',
|
||||
'-1.5',
|
||||
'2.5',
|
||||
'-2.5',
|
||||
] as $number) {
|
||||
$func_ret = bcround($number, 0, $mode);
|
||||
$method_ret = (new BcMath\Number($number))->round(0, $mode);
|
||||
if ($method_ret->compare($func_ret) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
var_dump($number, $mode, $func_ret, $method_ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (RoundingMode::cases() as $mode) {
|
||||
foreach ([
|
||||
'1.2345678',
|
||||
'-1.2345678',
|
||||
] as $number) {
|
||||
$func_ret = bcround($number, 5, $mode);
|
||||
$method_ret = (new BcMath\Number($number))->round(5, $mode);
|
||||
if ($method_ret->compare($func_ret) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
var_dump($number, $mode, $func_ret, $method_ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo 'done!';
|
||||
?>
|
||||
--EXPECT--
|
||||
done!
|
37
ext/bcmath/tests/number/methods/sqrt.phpt
Normal file
37
ext/bcmath/tests/number/methods/sqrt.phpt
Normal file
|
@ -0,0 +1,37 @@
|
|||
--TEST--
|
||||
BcMath\Number sqrt()
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$radicants = [
|
||||
"15151324141414.412312232141241",
|
||||
"141241241241241248267654747412",
|
||||
"0.1322135476547459213732911312",
|
||||
];
|
||||
|
||||
foreach ($radicants as $radicant) {
|
||||
$method_ret = (new BcMath\Number($radicant))->sqrt();
|
||||
var_dump($method_ret);
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(33) "3892470.1850385973524458288799178"
|
||||
["scale"]=>
|
||||
int(25)
|
||||
}
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(26) "375820756799356.7439216735"
|
||||
["scale"]=>
|
||||
int(10)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(40) "0.36361180901442945486553617684111499023"
|
||||
["scale"]=>
|
||||
int(38)
|
||||
}
|
36
ext/bcmath/tests/number/methods/sqrt_with_scale.phpt
Normal file
36
ext/bcmath/tests/number/methods/sqrt_with_scale.phpt
Normal file
|
@ -0,0 +1,36 @@
|
|||
--TEST--
|
||||
BcMath\Number sqrt() with scale
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$radicants = [
|
||||
"0",
|
||||
"0.00",
|
||||
"-0",
|
||||
"-0.00",
|
||||
"15151324141414.412312232141241",
|
||||
"141241241241241248267654747412",
|
||||
"0.1322135476547459213732911312",
|
||||
"14.14",
|
||||
"0.15",
|
||||
"15",
|
||||
"1",
|
||||
];
|
||||
$scales = [0, 10];
|
||||
|
||||
foreach ($scales as $scale) {
|
||||
foreach ($radicants as $radicant) {
|
||||
$func_ret = bcsqrt($radicant, $scale);
|
||||
$method_ret = (new BcMath\Number($radicant))->sqrt($scale);
|
||||
if ($method_ret->compare($func_ret) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
var_dump($radicant, $scale, $func_ret, $method_ret, ((string) $method_ret) === $func_ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
echo 'done!';
|
||||
?>
|
||||
--EXPECT--
|
||||
done!
|
142
ext/bcmath/tests/number/methods/sub.phpt
Normal file
142
ext/bcmath/tests/number/methods/sub.phpt
Normal file
|
@ -0,0 +1,142 @@
|
|||
--TEST--
|
||||
BcMath\Number sub()
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values1 = ['100.012', '-100.012'];
|
||||
|
||||
$values2 = [
|
||||
[100, 'int'],
|
||||
[-30, 'int'],
|
||||
['-20', 'string'],
|
||||
['0.01', 'string'],
|
||||
['-0.40', 'string'],
|
||||
[new BcMath\Number('80.3'), 'object'],
|
||||
[new BcMath\Number('-50.6'), 'object'],
|
||||
];
|
||||
|
||||
foreach ($values1 as $value1) {
|
||||
$num = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values2 as [$value2, $type]) {
|
||||
echo "{$value1} - {$value2}: {$type}\n";
|
||||
$ret = $num->sub($value2);
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100.012 - 100: int
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(5) "0.012"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 - -30: int
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(7) "130.012"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 - -20: string
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(7) "120.012"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 - 0.01: string
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(7) "100.002"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 - -0.40: string
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(7) "100.412"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 - 80.3: object
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(6) "19.712"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
100.012 - -50.6: object
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(7) "150.612"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 - 100: int
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(8) "-200.012"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 - -30: int
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(7) "-70.012"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 - -20: string
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(7) "-80.012"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 - 0.01: string
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(8) "-100.022"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 - -0.40: string
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(7) "-99.612"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 - 80.3: object
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(8) "-180.312"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-100.012 - -50.6: object
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(7) "-49.412"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
41
ext/bcmath/tests/number/methods/sub_with_scale.phpt
Normal file
41
ext/bcmath/tests/number/methods/sub_with_scale.phpt
Normal file
|
@ -0,0 +1,41 @@
|
|||
--TEST--
|
||||
BcMath\Number sub() with scale
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$scales = [0, 1, 2, 3, 4];
|
||||
|
||||
$values1 = ['100.012', '-100.012'];
|
||||
|
||||
$values2 = [
|
||||
[100, 'int'],
|
||||
[-30, 'int'],
|
||||
['100.012', 'string'],
|
||||
['-100.012', 'string'],
|
||||
['-20', 'string'],
|
||||
['0.01', 'string'],
|
||||
['-0.40', 'string'],
|
||||
[new BcMath\Number('80.3'), 'object'],
|
||||
[new BcMath\Number('-50.6'), 'object'],
|
||||
];
|
||||
|
||||
foreach ($scales as $scale) {
|
||||
foreach ($values1 as $value1) {
|
||||
$num = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values2 as [$value2, $type]) {
|
||||
$func_ret = bcsub($value1, (string) $value2, $scale);
|
||||
$method_ret = $num->sub($value2, $scale);
|
||||
if ($method_ret->compare($func_ret) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
var_dump($value1, $value2, $scale, $func_ret, $method_ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
echo 'done!';
|
||||
?>
|
||||
--EXPECT--
|
||||
done!
|
59
ext/bcmath/tests/number/operators/add_int.phpt
Normal file
59
ext/bcmath/tests/number/operators/add_int.phpt
Normal file
|
@ -0,0 +1,59 @@
|
|||
--TEST--
|
||||
BcMath\Number add int by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
100,
|
||||
'-20',
|
||||
];
|
||||
|
||||
foreach ($values as $value1) {
|
||||
$num1 = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values as $value2) {
|
||||
echo "{$value1} + {$value2}\n";
|
||||
$ret = $num1 + ((int) $value2);
|
||||
$ret2 = ((int) $value1) + (new BcMath\Number($value2));
|
||||
if ($ret->compare($ret2) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
}
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100 + 100
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(3) "200"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 + -20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(2) "80"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 + 100
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(2) "80"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 + -20
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(3) "-40"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
154
ext/bcmath/tests/number/operators/add_object.phpt
Normal file
154
ext/bcmath/tests/number/operators/add_object.phpt
Normal file
|
@ -0,0 +1,154 @@
|
|||
--TEST--
|
||||
BcMath\Number add object by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
100,
|
||||
'-20',
|
||||
'0.01',
|
||||
'-0.40',
|
||||
];
|
||||
|
||||
foreach ($values as $value1) {
|
||||
$num1 = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values as $value2) {
|
||||
echo "{$value1} + {$value2}\n";
|
||||
$num2 = new BcMath\Number($value2);
|
||||
$ret = $num1 + $num2;
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100 + 100
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(3) "200"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 + -20
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(2) "80"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 + 0.01
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(6) "100.01"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
100 + -0.40
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(5) "99.60"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-20 + 100
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(2) "80"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 + -20
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(3) "-40"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 + 0.01
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(6) "-19.99"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-20 + -0.40
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(6) "-20.40"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 + 100
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(6) "100.01"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 + -20
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(6) "-19.99"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 + 0.01
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.02"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 + -0.40
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.39"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 + 100
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(5) "99.60"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 + -20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(6) "-20.40"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 + 0.01
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.39"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 + -0.40
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.80"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
157
ext/bcmath/tests/number/operators/add_string.phpt
Normal file
157
ext/bcmath/tests/number/operators/add_string.phpt
Normal file
|
@ -0,0 +1,157 @@
|
|||
--TEST--
|
||||
BcMath\Number add string by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
100,
|
||||
'-20',
|
||||
'0.01',
|
||||
'-0.40',
|
||||
];
|
||||
|
||||
foreach ($values as $value1) {
|
||||
$num1 = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values as $value2) {
|
||||
echo "{$value1} + {$value2}\n";
|
||||
$ret = $num1 + ((string) $value2);
|
||||
$ret2 = ((string) $value1) + (new BcMath\Number($value2));
|
||||
if ($ret->compare($ret2) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
}
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100 + 100
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(3) "200"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 + -20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(2) "80"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 + 0.01
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(6) "100.01"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
100 + -0.40
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(5) "99.60"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-20 + 100
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(2) "80"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 + -20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(3) "-40"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 + 0.01
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(6) "-19.99"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-20 + -0.40
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(6) "-20.40"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 + 100
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(6) "100.01"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 + -20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(6) "-19.99"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 + 0.01
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.02"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 + -0.40
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.39"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 + 100
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(5) "99.60"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 + -20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(6) "-20.40"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 + 0.01
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.39"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 + -0.40
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.80"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
52
ext/bcmath/tests/number/operators/calc_array.phpt
Normal file
52
ext/bcmath/tests/number/operators/calc_array.phpt
Normal file
|
@ -0,0 +1,52 @@
|
|||
--TEST--
|
||||
BcMath\Number calc array by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
$num = new BcMath\Number(100);
|
||||
$array = [1];
|
||||
|
||||
try {
|
||||
$num + $array;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num - $array;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num * $array;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num / $array;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num % $array;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num ** $array;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
Unsupported operand types: BcMath\Number + array
|
||||
Unsupported operand types: BcMath\Number - array
|
||||
Unsupported operand types: BcMath\Number * array
|
||||
Unsupported operand types: BcMath\Number / array
|
||||
Unsupported operand types: BcMath\Number % array
|
||||
Unsupported operand types: BcMath\Number ** array
|
27
ext/bcmath/tests/number/operators/calc_float.phpt
Normal file
27
ext/bcmath/tests/number/operators/calc_float.phpt
Normal file
|
@ -0,0 +1,27 @@
|
|||
--TEST--
|
||||
BcMath\Number calc float by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
$num = new BcMath\Number(100);
|
||||
|
||||
$num + 1.01;
|
||||
$num - 1.01;
|
||||
$num * 1.01;
|
||||
$num / 1.01;
|
||||
$num % 1.01;
|
||||
$num ** 1.01;
|
||||
?>
|
||||
--EXPECTF--
|
||||
Deprecated: Implicit conversion from float 1.01 to int loses precision in %s
|
||||
|
||||
Deprecated: Implicit conversion from float 1.01 to int loses precision in %s
|
||||
|
||||
Deprecated: Implicit conversion from float 1.01 to int loses precision in %s
|
||||
|
||||
Deprecated: Implicit conversion from float 1.01 to int loses precision in %s
|
||||
|
||||
Deprecated: Implicit conversion from float 1.01 to int loses precision in %s
|
||||
|
||||
Deprecated: Implicit conversion from float 1.01 to int loses precision in %s
|
|
@ -0,0 +1,51 @@
|
|||
--TEST--
|
||||
BcMath\Number calc non-numeric string by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
$num = new BcMath\Number(100);
|
||||
|
||||
try {
|
||||
$num + 'a';
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num - 'a';
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num * 'a';
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num / 'a';
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num % 'a';
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num ** 'a';
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
Number is not well-formed
|
||||
Number is not well-formed
|
||||
Number is not well-formed
|
||||
Number is not well-formed
|
||||
Number is not well-formed
|
||||
Number is not well-formed
|
52
ext/bcmath/tests/number/operators/calc_other_class.phpt
Normal file
52
ext/bcmath/tests/number/operators/calc_other_class.phpt
Normal file
|
@ -0,0 +1,52 @@
|
|||
--TEST--
|
||||
BcMath\Number calc other class by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
$num = new BcMath\Number(100);
|
||||
$other = new stdClass();
|
||||
|
||||
try {
|
||||
$num + $other;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num - $other;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num * $other;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num / $other;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num % $other;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num ** $other;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
Unsupported operand types: BcMath\Number + stdClass
|
||||
Unsupported operand types: BcMath\Number - stdClass
|
||||
Unsupported operand types: BcMath\Number * stdClass
|
||||
Unsupported operand types: BcMath\Number / stdClass
|
||||
Unsupported operand types: BcMath\Number % stdClass
|
||||
Unsupported operand types: BcMath\Number ** stdClass
|
58
ext/bcmath/tests/number/operators/calc_undef.phpt
Normal file
58
ext/bcmath/tests/number/operators/calc_undef.phpt
Normal file
|
@ -0,0 +1,58 @@
|
|||
--TEST--
|
||||
BcMath\Number calc undefined var by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
$num = new BcMath\Number(100);
|
||||
|
||||
try {
|
||||
$num + $undef;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num - $undef;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num * $undef;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num / $undef;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num % $undef;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num ** $undef;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: Undefined variable $undef in %s
|
||||
|
||||
Warning: Undefined variable $undef in %s
|
||||
|
||||
Warning: Undefined variable $undef in %s
|
||||
|
||||
Warning: Undefined variable $undef in %s
|
||||
Division by zero
|
||||
|
||||
Warning: Undefined variable $undef in %s
|
||||
Modulo by zero
|
||||
|
||||
Warning: Undefined variable $undef in %s
|
195
ext/bcmath/tests/number/operators/compare.phpt
Normal file
195
ext/bcmath/tests/number/operators/compare.phpt
Normal file
|
@ -0,0 +1,195 @@
|
|||
--TEST--
|
||||
BcMath\Number compare by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values2 = [
|
||||
[99, 'int'],
|
||||
['99.9999', 'string'],
|
||||
[new BcMath\Number('99.9999'), 'object'],
|
||||
[100, 'int'],
|
||||
['100', 'string'],
|
||||
['100.0000', 'string'],
|
||||
[new BcMath\Number(100), 'object'],
|
||||
[new BcMath\Number('100.0000'), 'object'],
|
||||
[101, 'int'],
|
||||
['100.00001', 'string'],
|
||||
[new BcMath\Number('100.00001'), 'object'],
|
||||
];
|
||||
|
||||
$value1 = new BcMath\Number('100.0000');
|
||||
|
||||
foreach ($values2 as [$value2, $type2]) {
|
||||
echo "========== with {$type2} {$value2} ==========\n";
|
||||
echo "{$value1} > {$value2}: " . ($value1 > $value2 ? 'true' : 'false') . "\n";
|
||||
echo "{$value1} >= {$value2}: " . ($value1 >= $value2 ? 'true' : 'false') . "\n";
|
||||
echo "{$value1} == {$value2}: " . ($value1 == $value2 ? 'true' : 'false') . "\n";
|
||||
echo "{$value1} <= {$value2}: " . ($value1 <= $value2 ? 'true' : 'false') . "\n";
|
||||
echo "{$value1} < {$value2}: " . ($value1 < $value2 ? 'true' : 'false') . "\n";
|
||||
|
||||
echo "\ninversion\n";
|
||||
echo "{$value2} > {$value1}: " . ($value2 > $value1 ? 'true' : 'false') . "\n";
|
||||
echo "{$value2} >= {$value1}: " . ($value2 >= $value1 ? 'true' : 'false') . "\n";
|
||||
echo "{$value2} == {$value1}: " . ($value2 == $value1 ? 'true' : 'false') . "\n";
|
||||
echo "{$value2} <= {$value1}: " . ($value2 <= $value1 ? 'true' : 'false') . "\n";
|
||||
echo "{$value2} < {$value1}: " . ($value2 < $value1 ? 'true' : 'false') . "\n";
|
||||
|
||||
echo "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
========== with int 99 ==========
|
||||
100.0000 > 99: true
|
||||
100.0000 >= 99: true
|
||||
100.0000 == 99: false
|
||||
100.0000 <= 99: false
|
||||
100.0000 < 99: false
|
||||
|
||||
inversion
|
||||
99 > 100.0000: false
|
||||
99 >= 100.0000: false
|
||||
99 == 100.0000: false
|
||||
99 <= 100.0000: true
|
||||
99 < 100.0000: true
|
||||
|
||||
========== with string 99.9999 ==========
|
||||
100.0000 > 99.9999: true
|
||||
100.0000 >= 99.9999: true
|
||||
100.0000 == 99.9999: false
|
||||
100.0000 <= 99.9999: false
|
||||
100.0000 < 99.9999: false
|
||||
|
||||
inversion
|
||||
99.9999 > 100.0000: false
|
||||
99.9999 >= 100.0000: false
|
||||
99.9999 == 100.0000: false
|
||||
99.9999 <= 100.0000: true
|
||||
99.9999 < 100.0000: true
|
||||
|
||||
========== with object 99.9999 ==========
|
||||
100.0000 > 99.9999: true
|
||||
100.0000 >= 99.9999: true
|
||||
100.0000 == 99.9999: false
|
||||
100.0000 <= 99.9999: false
|
||||
100.0000 < 99.9999: false
|
||||
|
||||
inversion
|
||||
99.9999 > 100.0000: false
|
||||
99.9999 >= 100.0000: false
|
||||
99.9999 == 100.0000: false
|
||||
99.9999 <= 100.0000: true
|
||||
99.9999 < 100.0000: true
|
||||
|
||||
========== with int 100 ==========
|
||||
100.0000 > 100: false
|
||||
100.0000 >= 100: true
|
||||
100.0000 == 100: true
|
||||
100.0000 <= 100: true
|
||||
100.0000 < 100: false
|
||||
|
||||
inversion
|
||||
100 > 100.0000: false
|
||||
100 >= 100.0000: true
|
||||
100 == 100.0000: true
|
||||
100 <= 100.0000: true
|
||||
100 < 100.0000: false
|
||||
|
||||
========== with string 100 ==========
|
||||
100.0000 > 100: false
|
||||
100.0000 >= 100: true
|
||||
100.0000 == 100: true
|
||||
100.0000 <= 100: true
|
||||
100.0000 < 100: false
|
||||
|
||||
inversion
|
||||
100 > 100.0000: false
|
||||
100 >= 100.0000: true
|
||||
100 == 100.0000: true
|
||||
100 <= 100.0000: true
|
||||
100 < 100.0000: false
|
||||
|
||||
========== with string 100.0000 ==========
|
||||
100.0000 > 100.0000: false
|
||||
100.0000 >= 100.0000: true
|
||||
100.0000 == 100.0000: true
|
||||
100.0000 <= 100.0000: true
|
||||
100.0000 < 100.0000: false
|
||||
|
||||
inversion
|
||||
100.0000 > 100.0000: false
|
||||
100.0000 >= 100.0000: true
|
||||
100.0000 == 100.0000: true
|
||||
100.0000 <= 100.0000: true
|
||||
100.0000 < 100.0000: false
|
||||
|
||||
========== with object 100 ==========
|
||||
100.0000 > 100: false
|
||||
100.0000 >= 100: true
|
||||
100.0000 == 100: true
|
||||
100.0000 <= 100: true
|
||||
100.0000 < 100: false
|
||||
|
||||
inversion
|
||||
100 > 100.0000: false
|
||||
100 >= 100.0000: true
|
||||
100 == 100.0000: true
|
||||
100 <= 100.0000: true
|
||||
100 < 100.0000: false
|
||||
|
||||
========== with object 100.0000 ==========
|
||||
100.0000 > 100.0000: false
|
||||
100.0000 >= 100.0000: true
|
||||
100.0000 == 100.0000: true
|
||||
100.0000 <= 100.0000: true
|
||||
100.0000 < 100.0000: false
|
||||
|
||||
inversion
|
||||
100.0000 > 100.0000: false
|
||||
100.0000 >= 100.0000: true
|
||||
100.0000 == 100.0000: true
|
||||
100.0000 <= 100.0000: true
|
||||
100.0000 < 100.0000: false
|
||||
|
||||
========== with int 101 ==========
|
||||
100.0000 > 101: false
|
||||
100.0000 >= 101: false
|
||||
100.0000 == 101: false
|
||||
100.0000 <= 101: true
|
||||
100.0000 < 101: true
|
||||
|
||||
inversion
|
||||
101 > 100.0000: true
|
||||
101 >= 100.0000: true
|
||||
101 == 100.0000: false
|
||||
101 <= 100.0000: false
|
||||
101 < 100.0000: false
|
||||
|
||||
========== with string 100.00001 ==========
|
||||
100.0000 > 100.00001: false
|
||||
100.0000 >= 100.00001: false
|
||||
100.0000 == 100.00001: false
|
||||
100.0000 <= 100.00001: true
|
||||
100.0000 < 100.00001: true
|
||||
|
||||
inversion
|
||||
100.00001 > 100.0000: true
|
||||
100.00001 >= 100.0000: true
|
||||
100.00001 == 100.0000: false
|
||||
100.00001 <= 100.0000: false
|
||||
100.00001 < 100.0000: false
|
||||
|
||||
========== with object 100.00001 ==========
|
||||
100.0000 > 100.00001: false
|
||||
100.0000 >= 100.00001: false
|
||||
100.0000 == 100.00001: false
|
||||
100.0000 <= 100.00001: true
|
||||
100.0000 < 100.00001: true
|
||||
|
||||
inversion
|
||||
100.00001 > 100.0000: true
|
||||
100.00001 >= 100.0000: true
|
||||
100.00001 == 100.0000: false
|
||||
100.00001 <= 100.0000: false
|
||||
100.00001 < 100.0000: false
|
115
ext/bcmath/tests/number/operators/compound_assignment.phpt
Normal file
115
ext/bcmath/tests/number/operators/compound_assignment.phpt
Normal file
|
@ -0,0 +1,115 @@
|
|||
--TEST--
|
||||
BcMath\Number operator compound assignment
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
echo "========== add ==========\n";
|
||||
$num = new BcMath\Number(100);
|
||||
$num_old = $num;
|
||||
$num += 100;
|
||||
echo $num . "\n";
|
||||
$num += '50';
|
||||
echo $num . "\n";
|
||||
$num += (new BcMath\Number(30));
|
||||
echo $num . "\n";
|
||||
echo 'old: ' . $num_old . "\n";
|
||||
echo "\n";
|
||||
|
||||
echo "========== sub ==========\n";
|
||||
$num = new BcMath\Number(100);
|
||||
$num_old = $num;
|
||||
$num -= 100;
|
||||
echo $num . "\n";
|
||||
$num -= '50';
|
||||
echo $num . "\n";
|
||||
$num -= (new BcMath\Number(30));
|
||||
echo $num . "\n";
|
||||
echo 'old: ' . $num_old . "\n";
|
||||
echo "\n";
|
||||
|
||||
echo "========== mul ==========\n";
|
||||
$num = new BcMath\Number(100);
|
||||
$num_old = $num;
|
||||
$num *= 100;
|
||||
echo $num . "\n";
|
||||
$num *= '50';
|
||||
echo $num . "\n";
|
||||
$num *= (new BcMath\Number(30));
|
||||
echo $num . "\n";
|
||||
echo 'old: ' . $num_old . "\n";
|
||||
echo "\n";
|
||||
|
||||
echo "========== div ==========\n";
|
||||
$num = new BcMath\Number(100);
|
||||
$num_old = $num;
|
||||
$num /= 100;
|
||||
echo $num . "\n";
|
||||
$num /= '50';
|
||||
echo $num . "\n";
|
||||
$num /= (new BcMath\Number(30));
|
||||
echo $num . "\n";
|
||||
echo 'old: ' . $num_old . "\n";
|
||||
echo "\n";
|
||||
|
||||
echo "========== mod ==========\n";
|
||||
$num = new BcMath\Number(1000);
|
||||
$num_old = $num;
|
||||
$num %= 90;
|
||||
echo $num . "\n";
|
||||
$num %= '30';
|
||||
echo $num . "\n";
|
||||
$num %= (new BcMath\Number(6));
|
||||
echo $num . "\n";
|
||||
echo 'old: ' . $num_old . "\n";
|
||||
echo "\n";
|
||||
|
||||
echo "========== pow ==========\n";
|
||||
$num = new BcMath\Number(10);
|
||||
$num_old = $num;
|
||||
$num **= 2;
|
||||
echo $num . "\n";
|
||||
$num **= '3';
|
||||
echo $num . "\n";
|
||||
$num **= (new BcMath\Number(0));
|
||||
echo $num . "\n";
|
||||
echo 'old: ' . $num_old . "\n";
|
||||
echo "\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
========== add ==========
|
||||
200
|
||||
250
|
||||
280
|
||||
old: 100
|
||||
|
||||
========== sub ==========
|
||||
0
|
||||
-50
|
||||
-80
|
||||
old: 100
|
||||
|
||||
========== mul ==========
|
||||
10000
|
||||
500000
|
||||
15000000
|
||||
old: 100
|
||||
|
||||
========== div ==========
|
||||
1
|
||||
0.02
|
||||
0.000666666666
|
||||
old: 100
|
||||
|
||||
========== mod ==========
|
||||
10
|
||||
10
|
||||
4
|
||||
old: 1000
|
||||
|
||||
========== pow ==========
|
||||
100
|
||||
1000000
|
||||
1
|
||||
old: 10
|
93
ext/bcmath/tests/number/operators/decrement.phpt
Normal file
93
ext/bcmath/tests/number/operators/decrement.phpt
Normal file
|
@ -0,0 +1,93 @@
|
|||
--TEST--
|
||||
BcMath\Number decrement
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
100,
|
||||
'-20',
|
||||
'0.01',
|
||||
'-0.40',
|
||||
];
|
||||
|
||||
foreach ($values as $value) {
|
||||
echo "========== {$value}-- ==========\n";
|
||||
$num = new BcMath\Number($value);
|
||||
$num_old = $num;
|
||||
|
||||
$num--;
|
||||
echo '$num:' . "\n";
|
||||
var_dump($num);
|
||||
|
||||
echo '$num_old:' . "\n";
|
||||
var_dump($num_old);
|
||||
|
||||
echo "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
========== 100-- ==========
|
||||
$num:
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(2) "99"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
$num_old:
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(3) "100"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
========== -20-- ==========
|
||||
$num:
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(3) "-21"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
$num_old:
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(3) "-20"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
========== 0.01-- ==========
|
||||
$num:
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.99"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
$num_old:
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.01"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
========== -0.40-- ==========
|
||||
$num:
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(5) "-1.40"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
$num_old:
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.40"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
53
ext/bcmath/tests/number/operators/div_by_zero.phpt
Normal file
53
ext/bcmath/tests/number/operators/div_by_zero.phpt
Normal file
|
@ -0,0 +1,53 @@
|
|||
--TEST--
|
||||
BcMath\Number div by zero by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
$num = new BcMath\Number(100);
|
||||
|
||||
try {
|
||||
$num / 0;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num / '0';
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num / (new BcMath\Number(0));
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
$zero = new BcMath\Number(0);
|
||||
|
||||
try {
|
||||
100 / $zero;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
'100' / $zero;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num / $zero;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
Division by zero
|
||||
Division by zero
|
||||
Division by zero
|
||||
Division by zero
|
||||
Division by zero
|
||||
Division by zero
|
100
ext/bcmath/tests/number/operators/div_int.phpt
Normal file
100
ext/bcmath/tests/number/operators/div_int.phpt
Normal file
|
@ -0,0 +1,100 @@
|
|||
--TEST--
|
||||
BcMath\Number div int by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
100,
|
||||
'-20',
|
||||
3,
|
||||
];
|
||||
|
||||
foreach ($values as $value1) {
|
||||
$num1 = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values as $value2) {
|
||||
echo "{$value1} / {$value2}\n";
|
||||
$ret = $num1 / ((int) $value2);
|
||||
$ret2 = ((int) $value1) / (new BcMath\Number($value2));
|
||||
if ($ret->compare($ret2) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
}
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100 / 100
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 / -20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(2) "-5"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 / 3
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(13) "33.3333333333"
|
||||
["scale"]=>
|
||||
int(10)
|
||||
}
|
||||
|
||||
-20 / 100
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(4) "-0.2"
|
||||
["scale"]=>
|
||||
int(1)
|
||||
}
|
||||
|
||||
-20 / -20
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 / 3
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(13) "-6.6666666666"
|
||||
["scale"]=>
|
||||
int(10)
|
||||
}
|
||||
|
||||
3 / 100
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.03"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
3 / -20
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.15"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
3 / 3
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
227
ext/bcmath/tests/number/operators/div_object.phpt
Normal file
227
ext/bcmath/tests/number/operators/div_object.phpt
Normal file
|
@ -0,0 +1,227 @@
|
|||
--TEST--
|
||||
BcMath\Number div object by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
100,
|
||||
'-20',
|
||||
'0.01',
|
||||
'-0.40',
|
||||
3,
|
||||
];
|
||||
|
||||
foreach ($values as $value1) {
|
||||
$num1 = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values as $value2) {
|
||||
echo "{$value1} / {$value2}\n";
|
||||
$num2 = new BcMath\Number($value2);
|
||||
$ret = $num1 / $num2;
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100 / 100
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 / -20
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(2) "-5"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 / 0.01
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(5) "10000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 / -0.40
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(4) "-250"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 / 3
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(13) "33.3333333333"
|
||||
["scale"]=>
|
||||
int(10)
|
||||
}
|
||||
|
||||
-20 / 100
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(4) "-0.2"
|
||||
["scale"]=>
|
||||
int(1)
|
||||
}
|
||||
|
||||
-20 / -20
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 / 0.01
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(5) "-2000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 / -0.40
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(2) "50"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 / 3
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(13) "-6.6666666666"
|
||||
["scale"]=>
|
||||
int(10)
|
||||
}
|
||||
|
||||
0.01 / 100
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.0001"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
0.01 / -20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(7) "-0.0005"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
0.01 / 0.01
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(4) "1.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 / -0.40
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(6) "-0.025"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
0.01 / 3
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(14) "0.003333333333"
|
||||
["scale"]=>
|
||||
int(12)
|
||||
}
|
||||
|
||||
-0.40 / 100
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(6) "-0.004"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-0.40 / -20
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.02"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 / 0.01
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(6) "-40.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 / -0.40
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(4) "1.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 / 3
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(15) "-0.133333333333"
|
||||
["scale"]=>
|
||||
int(12)
|
||||
}
|
||||
|
||||
3 / 100
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.03"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
3 / -20
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.15"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
3 / 0.01
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(3) "300"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
3 / -0.40
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(4) "-7.5"
|
||||
["scale"]=>
|
||||
int(1)
|
||||
}
|
||||
|
||||
3 / 3
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
230
ext/bcmath/tests/number/operators/div_string.phpt
Normal file
230
ext/bcmath/tests/number/operators/div_string.phpt
Normal file
|
@ -0,0 +1,230 @@
|
|||
--TEST--
|
||||
BcMath\Number div string by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
100,
|
||||
'-20',
|
||||
'0.01',
|
||||
'-0.40',
|
||||
3,
|
||||
];
|
||||
|
||||
foreach ($values as $value1) {
|
||||
$num1 = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values as $value2) {
|
||||
echo "{$value1} / {$value2}\n";
|
||||
$ret = $num1 / ((string) $value2);
|
||||
$ret2 = ((string) $value1) / (new BcMath\Number($value2));
|
||||
if ($ret->compare($ret2) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
}
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100 / 100
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 / -20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(2) "-5"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 / 0.01
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(5) "10000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 / -0.40
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(4) "-250"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 / 3
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(13) "33.3333333333"
|
||||
["scale"]=>
|
||||
int(10)
|
||||
}
|
||||
|
||||
-20 / 100
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(4) "-0.2"
|
||||
["scale"]=>
|
||||
int(1)
|
||||
}
|
||||
|
||||
-20 / -20
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 / 0.01
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(5) "-2000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 / -0.40
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(2) "50"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 / 3
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(13) "-6.6666666666"
|
||||
["scale"]=>
|
||||
int(10)
|
||||
}
|
||||
|
||||
0.01 / 100
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.0001"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
0.01 / -20
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(7) "-0.0005"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
0.01 / 0.01
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(4) "1.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 / -0.40
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(6) "-0.025"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
0.01 / 3
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(14) "0.003333333333"
|
||||
["scale"]=>
|
||||
int(12)
|
||||
}
|
||||
|
||||
-0.40 / 100
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(6) "-0.004"
|
||||
["scale"]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-0.40 / -20
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.02"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 / 0.01
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(6) "-40.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 / -0.40
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(4) "1.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 / 3
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(15) "-0.133333333333"
|
||||
["scale"]=>
|
||||
int(12)
|
||||
}
|
||||
|
||||
3 / 100
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.03"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
3 / -20
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.15"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
3 / 0.01
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(3) "300"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
3 / -0.40
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(4) "-7.5"
|
||||
["scale"]=>
|
||||
int(1)
|
||||
}
|
||||
|
||||
3 / 3
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
93
ext/bcmath/tests/number/operators/increment.phpt
Normal file
93
ext/bcmath/tests/number/operators/increment.phpt
Normal file
|
@ -0,0 +1,93 @@
|
|||
--TEST--
|
||||
BcMath\Number increment
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
100,
|
||||
'-20',
|
||||
'0.01',
|
||||
'-0.40',
|
||||
];
|
||||
|
||||
foreach ($values as $value) {
|
||||
echo "========== {$value}++ ==========\n";
|
||||
$num = new BcMath\Number($value);
|
||||
$num_old = $num;
|
||||
|
||||
$num++;
|
||||
echo '$num:' . "\n";
|
||||
var_dump($num);
|
||||
|
||||
echo '$num_old:' . "\n";
|
||||
var_dump($num_old);
|
||||
|
||||
echo "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
========== 100++ ==========
|
||||
$num:
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(3) "101"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
$num_old:
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(3) "100"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
========== -20++ ==========
|
||||
$num:
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(3) "-19"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
$num_old:
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(3) "-20"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
========== 0.01++ ==========
|
||||
$num:
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(4) "1.01"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
$num_old:
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.01"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
========== -0.40++ ==========
|
||||
$num:
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.60"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
$num_old:
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.40"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
53
ext/bcmath/tests/number/operators/mod_by_zero.phpt
Normal file
53
ext/bcmath/tests/number/operators/mod_by_zero.phpt
Normal file
|
@ -0,0 +1,53 @@
|
|||
--TEST--
|
||||
BcMath\Number mod by zero by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
$num = new BcMath\Number(100);
|
||||
|
||||
try {
|
||||
$num % 0;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num % '0';
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num % (new BcMath\Number(0));
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
$zero = new BcMath\Number(0);
|
||||
|
||||
try {
|
||||
100 % $zero;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
'100' % $zero;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num % $zero;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
Modulo by zero
|
||||
Modulo by zero
|
||||
Modulo by zero
|
||||
Modulo by zero
|
||||
Modulo by zero
|
||||
Modulo by zero
|
100
ext/bcmath/tests/number/operators/mod_int.phpt
Normal file
100
ext/bcmath/tests/number/operators/mod_int.phpt
Normal file
|
@ -0,0 +1,100 @@
|
|||
--TEST--
|
||||
BcMath\Number mod int by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
100,
|
||||
'-20',
|
||||
9,
|
||||
];
|
||||
|
||||
foreach ($values as $value1) {
|
||||
$num1 = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values as $value2) {
|
||||
echo "{$value1} % {$value2}\n";
|
||||
$ret = $num1 % ((int) $value2);
|
||||
$ret2 = ((string) $value1) % (new BcMath\Number($value2));
|
||||
if ($ret->compare($ret2) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
}
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100 % 100
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 % -20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 % 9
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 % 100
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(3) "-20"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 % -20
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 % 9
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(2) "-2"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
9 % 100
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "9"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
9 % -20
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "9"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
9 % 9
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
154
ext/bcmath/tests/number/operators/mod_object.phpt
Normal file
154
ext/bcmath/tests/number/operators/mod_object.phpt
Normal file
|
@ -0,0 +1,154 @@
|
|||
--TEST--
|
||||
BcMath\Number mod object by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
100,
|
||||
'-20',
|
||||
'0.01',
|
||||
'-0.40',
|
||||
];
|
||||
|
||||
foreach ($values as $value1) {
|
||||
$num1 = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values as $value2) {
|
||||
echo "{$value1} % {$value2}\n";
|
||||
$num2 = new BcMath\Number($value2);
|
||||
$ret = $num1 % $num2;
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100 % 100
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 % -20
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 % 0.01
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
100 % -0.40
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-20 % 100
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(3) "-20"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 % -20
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 % 0.01
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-20 % -0.40
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 % 100
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.01"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 % -20
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.01"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 % 0.01
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 % -0.40
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.01"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 % 100
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.40"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 % -20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.40"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 % 0.01
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 % -0.40
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
100
ext/bcmath/tests/number/operators/mod_string.phpt
Normal file
100
ext/bcmath/tests/number/operators/mod_string.phpt
Normal file
|
@ -0,0 +1,100 @@
|
|||
--TEST--
|
||||
BcMath\Number mod string by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
100,
|
||||
'-20',
|
||||
9,
|
||||
];
|
||||
|
||||
foreach ($values as $value1) {
|
||||
$num1 = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values as $value2) {
|
||||
echo "{$value1} % {$value2}\n";
|
||||
$ret = $num1 % ((string) $value2);
|
||||
$ret2 = ((string) $value1) % (new BcMath\Number($value2));
|
||||
if ($ret->compare($ret2) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
}
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100 % 100
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 % -20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 % 9
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 % 100
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(3) "-20"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 % -20
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 % 9
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(2) "-2"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
9 % 100
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "9"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
9 % -20
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "9"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
9 % 9
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
59
ext/bcmath/tests/number/operators/mul_int.phpt
Normal file
59
ext/bcmath/tests/number/operators/mul_int.phpt
Normal file
|
@ -0,0 +1,59 @@
|
|||
--TEST--
|
||||
BcMath\Number mul int by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
100,
|
||||
'-20',
|
||||
];
|
||||
|
||||
foreach ($values as $value1) {
|
||||
$num1 = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values as $value2) {
|
||||
echo "{$value1} * {$value2}\n";
|
||||
$ret = $num1 * ((int) $value2);
|
||||
$ret2 = ((int) $value1) * (new BcMath\Number($value2));
|
||||
if ($ret->compare($ret2) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
}
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100 * 100
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(5) "10000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 * -20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(5) "-2000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 * 100
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(5) "-2000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 * -20
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(3) "400"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
154
ext/bcmath/tests/number/operators/mul_object.phpt
Normal file
154
ext/bcmath/tests/number/operators/mul_object.phpt
Normal file
|
@ -0,0 +1,154 @@
|
|||
--TEST--
|
||||
BcMath\Number mul object by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
100,
|
||||
'-20',
|
||||
'0.01',
|
||||
'-0.40',
|
||||
];
|
||||
|
||||
foreach ($values as $value1) {
|
||||
$num1 = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values as $value2) {
|
||||
echo "{$value1} * {$value2}\n";
|
||||
$num2 = new BcMath\Number($value2);
|
||||
$ret = $num1 * $num2;
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100 * 100
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(5) "10000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 * -20
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(5) "-2000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 * 0.01
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(4) "1.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
100 * -0.40
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(6) "-40.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-20 * 100
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(5) "-2000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 * -20
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(3) "400"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 * 0.01
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.20"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-20 * -0.40
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(4) "8.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 * 100
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(4) "1.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 * -20
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.20"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 * 0.01
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.0001"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
0.01 * -0.40
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(7) "-0.0040"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
-0.40 * 100
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(6) "-40.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 * -20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(4) "8.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 * 0.01
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(7) "-0.0040"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
-0.40 * -0.40
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.1600"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
157
ext/bcmath/tests/number/operators/mul_string.phpt
Normal file
157
ext/bcmath/tests/number/operators/mul_string.phpt
Normal file
|
@ -0,0 +1,157 @@
|
|||
--TEST--
|
||||
BcMath\Number mul string by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
100,
|
||||
'-20',
|
||||
'0.01',
|
||||
'-0.40',
|
||||
];
|
||||
|
||||
foreach ($values as $value1) {
|
||||
$num1 = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values as $value2) {
|
||||
echo "{$value1} * {$value2}\n";
|
||||
$ret = $num1 * ((string) $value2);
|
||||
$ret2 = ((string) $value1) * (new BcMath\Number($value2));
|
||||
if ($ret->compare($ret2) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
}
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100 * 100
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(5) "10000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 * -20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(5) "-2000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 * 0.01
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(4) "1.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
100 * -0.40
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(6) "-40.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-20 * 100
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(5) "-2000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 * -20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(3) "400"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 * 0.01
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.20"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-20 * -0.40
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(4) "8.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 * 100
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(4) "1.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 * -20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.20"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 * 0.01
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.0001"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
0.01 * -0.40
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(7) "-0.0040"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
-0.40 * 100
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(6) "-40.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 * -20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(4) "8.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 * 0.01
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(7) "-0.0040"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
-0.40 * -0.40
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.1600"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
156
ext/bcmath/tests/number/operators/pow_int.phpt
Normal file
156
ext/bcmath/tests/number/operators/pow_int.phpt
Normal file
|
@ -0,0 +1,156 @@
|
|||
--TEST--
|
||||
BcMath\Number pow int by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
100,
|
||||
'-20',
|
||||
3,
|
||||
];
|
||||
|
||||
$exponents = [
|
||||
2,
|
||||
'3',
|
||||
0,
|
||||
-1,
|
||||
-2,
|
||||
];
|
||||
|
||||
foreach ($values as $value) {
|
||||
$num1 = new BcMath\Number($value);
|
||||
|
||||
foreach ($exponents as $exponent) {
|
||||
echo "{$value} ** {$exponent}\n";
|
||||
$ret = $num1 ** ((int) $exponent);
|
||||
$ret2 = ((int) $value) ** (new BcMath\Number($exponent));
|
||||
if ($ret->compare($ret2) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
}
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100 ** 2
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(5) "10000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 ** 3
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(7) "1000000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 ** 0
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 ** -1
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.01"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
100 ** -2
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.0001"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
-20 ** 2
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(3) "400"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 ** 3
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(5) "-8000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 ** 0
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 ** -1
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.05"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-20 ** -2
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.0025"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
3 ** 2
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(1) "9"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
3 ** 3
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(2) "27"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
3 ** 0
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
3 ** -1
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(12) "0.3333333333"
|
||||
["scale"]=>
|
||||
int(10)
|
||||
}
|
||||
|
||||
3 ** -2
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(12) "0.1111111111"
|
||||
["scale"]=>
|
||||
int(10)
|
||||
}
|
235
ext/bcmath/tests/number/operators/pow_object.phpt
Normal file
235
ext/bcmath/tests/number/operators/pow_object.phpt
Normal file
|
@ -0,0 +1,235 @@
|
|||
--TEST--
|
||||
BcMath\Number pow object by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
100,
|
||||
'-20',
|
||||
'0.01',
|
||||
'-0.40',
|
||||
3,
|
||||
];
|
||||
|
||||
$exponents = [
|
||||
2,
|
||||
'3',
|
||||
0,
|
||||
-1,
|
||||
-2,
|
||||
];
|
||||
|
||||
foreach ($values as $value) {
|
||||
$num1 = new BcMath\Number($value);
|
||||
|
||||
foreach ($exponents as $exponent) {
|
||||
echo "{$value} ** {$exponent}\n";
|
||||
$num2 = new BcMath\Number($exponent);
|
||||
$ret = $num1 ** $num2;
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100 ** 2
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(5) "10000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 ** 3
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(7) "1000000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 ** 0
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 ** -1
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.01"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
100 ** -2
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.0001"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
-20 ** 2
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(3) "400"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 ** 3
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(5) "-8000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 ** 0
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 ** -1
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.05"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-20 ** -2
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.0025"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
0.01 ** 2
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.0001"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
0.01 ** 3
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(8) "0.000001"
|
||||
["scale"]=>
|
||||
int(6)
|
||||
}
|
||||
|
||||
0.01 ** 0
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
0.01 ** -1
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(6) "100.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 ** -2
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(8) "10000.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 ** 2
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.1600"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
-0.40 ** 3
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(9) "-0.064000"
|
||||
["scale"]=>
|
||||
int(6)
|
||||
}
|
||||
|
||||
-0.40 ** 0
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-0.40 ** -1
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(5) "-2.50"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 ** -2
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(4) "6.25"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
3 ** 2
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(1) "9"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
3 ** 3
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(2) "27"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
3 ** 0
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
3 ** -1
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(12) "0.3333333333"
|
||||
["scale"]=>
|
||||
int(10)
|
||||
}
|
||||
|
||||
3 ** -2
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(12) "0.1111111111"
|
||||
["scale"]=>
|
||||
int(10)
|
||||
}
|
238
ext/bcmath/tests/number/operators/pow_string.phpt
Normal file
238
ext/bcmath/tests/number/operators/pow_string.phpt
Normal file
|
@ -0,0 +1,238 @@
|
|||
--TEST--
|
||||
BcMath\Number pow string by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
100,
|
||||
'-20',
|
||||
'0.01',
|
||||
'-0.40',
|
||||
3,
|
||||
];
|
||||
|
||||
$exponents = [
|
||||
2,
|
||||
'3',
|
||||
0,
|
||||
-1,
|
||||
-2,
|
||||
];
|
||||
|
||||
foreach ($values as $value) {
|
||||
$num1 = new BcMath\Number($value);
|
||||
|
||||
foreach ($exponents as $exponent) {
|
||||
echo "{$value} ** {$exponent}\n";
|
||||
$ret = $num1 ** ((string) $exponent);
|
||||
$ret2 = ((string) $value) ** (new BcMath\Number($exponent));
|
||||
if ($ret->compare($ret2) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
}
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100 ** 2
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(5) "10000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 ** 3
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(7) "1000000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 ** 0
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 ** -1
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.01"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
100 ** -2
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.0001"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
-20 ** 2
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(3) "400"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 ** 3
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(5) "-8000"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 ** 0
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-20 ** -1
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.05"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-20 ** -2
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.0025"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
0.01 ** 2
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.0001"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
0.01 ** 3
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(8) "0.000001"
|
||||
["scale"]=>
|
||||
int(6)
|
||||
}
|
||||
|
||||
0.01 ** 0
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
0.01 ** -1
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(6) "100.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 ** -2
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(8) "10000.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 ** 2
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.1600"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
|
||||
-0.40 ** 3
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(9) "-0.064000"
|
||||
["scale"]=>
|
||||
int(6)
|
||||
}
|
||||
|
||||
-0.40 ** 0
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-0.40 ** -1
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(5) "-2.50"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
-0.40 ** -2
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(4) "6.25"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
3 ** 2
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "9"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
3 ** 3
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(2) "27"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
3 ** 0
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
3 ** -1
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(12) "0.3333333333"
|
||||
["scale"]=>
|
||||
int(10)
|
||||
}
|
||||
|
||||
3 ** -2
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(12) "0.1111111111"
|
||||
["scale"]=>
|
||||
int(10)
|
||||
}
|
59
ext/bcmath/tests/number/operators/sub_int.phpt
Normal file
59
ext/bcmath/tests/number/operators/sub_int.phpt
Normal file
|
@ -0,0 +1,59 @@
|
|||
--TEST--
|
||||
BcMath\Number sub int by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
100,
|
||||
'20',
|
||||
];
|
||||
|
||||
foreach ($values as $value1) {
|
||||
$num1 = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values as $value2) {
|
||||
echo "{$value1} - {$value2}\n";
|
||||
$ret = $num1 - ((int) $value2);
|
||||
$ret2 = ((int) $value1) - (new BcMath\Number($value2));
|
||||
if ($ret->compare($ret2) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
}
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100 - 100
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 - 20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(2) "80"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
20 - 100
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(3) "-80"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
20 - 20
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
154
ext/bcmath/tests/number/operators/sub_object.phpt
Normal file
154
ext/bcmath/tests/number/operators/sub_object.phpt
Normal file
|
@ -0,0 +1,154 @@
|
|||
--TEST--
|
||||
BcMath\Number sub object by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
100,
|
||||
'20',
|
||||
'0.01',
|
||||
'0.40',
|
||||
];
|
||||
|
||||
foreach ($values as $value1) {
|
||||
$num1 = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values as $value2) {
|
||||
echo "{$value1} - {$value2}\n";
|
||||
$num2 = new BcMath\Number($value2);
|
||||
$ret = $num1 - $num2;
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100 - 100
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 - 20
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(2) "80"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 - 0.01
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(5) "99.99"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
100 - 0.40
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(5) "99.60"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
20 - 100
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(3) "-80"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
20 - 20
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
20 - 0.01
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(5) "19.99"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
20 - 0.40
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(5) "19.60"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 - 100
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(6) "-99.99"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 - 20
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(6) "-19.99"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 - 0.01
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 - 0.40
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.39"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.40 - 100
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(6) "-99.60"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.40 - 20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(6) "-19.60"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.40 - 0.01
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.39"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.40 - 0.40
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
157
ext/bcmath/tests/number/operators/sub_string.phpt
Normal file
157
ext/bcmath/tests/number/operators/sub_string.phpt
Normal file
|
@ -0,0 +1,157 @@
|
|||
--TEST--
|
||||
BcMath\Number sub string by operator
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
100,
|
||||
'20',
|
||||
'0.01',
|
||||
'0.40',
|
||||
];
|
||||
|
||||
foreach ($values as $value1) {
|
||||
$num1 = new BcMath\Number($value1);
|
||||
|
||||
foreach ($values as $value2) {
|
||||
echo "{$value1} - {$value2}\n";
|
||||
$ret = $num1 - ((string) $value2);
|
||||
$ret2 = ((string) $value1) - (new BcMath\Number($value2));
|
||||
if ($ret->compare($ret2) !== 0) {
|
||||
echo "Result is incorrect.\n";
|
||||
}
|
||||
var_dump($ret);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
100 - 100
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 - 20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(2) "80"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
100 - 0.01
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(5) "99.99"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
100 - 0.40
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(5) "99.60"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
20 - 100
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(3) "-80"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
20 - 20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
20 - 0.01
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(5) "19.99"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
20 - 0.40
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(5) "19.60"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 - 100
|
||||
object(BcMath\Number)#2 (2) {
|
||||
["value"]=>
|
||||
string(6) "-99.99"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 - 20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(6) "-19.99"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 - 0.01
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.01 - 0.40
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(5) "-0.39"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.40 - 100
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(6) "-99.60"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.40 - 20
|
||||
object(BcMath\Number)#3 (2) {
|
||||
["value"]=>
|
||||
string(6) "-19.60"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.40 - 0.01
|
||||
object(BcMath\Number)#4 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.39"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
||||
|
||||
0.40 - 0.40
|
||||
object(BcMath\Number)#5 (2) {
|
||||
["value"]=>
|
||||
string(4) "0.00"
|
||||
["scale"]=>
|
||||
int(2)
|
||||
}
|
136
ext/bcmath/tests/number/properties_isset_empty_exists.phpt
Normal file
136
ext/bcmath/tests/number/properties_isset_empty_exists.phpt
Normal file
|
@ -0,0 +1,136 @@
|
|||
--TEST--
|
||||
BcMath\Number properties isset, empty, exists
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$zero = new BcMath\Number(0);
|
||||
$one = new BcMath\Number(1);
|
||||
$has_frac = new BcMath\Number('5.67');
|
||||
|
||||
echo "========== isset ==========\n";
|
||||
var_dump([
|
||||
'zero' => [
|
||||
'value' => isset($zero->value),
|
||||
'scale' => isset($zero->scale),
|
||||
],
|
||||
'one' => [
|
||||
'value' => isset($one->value),
|
||||
'scale' => isset($one->scale),
|
||||
],
|
||||
'has_frac' => [
|
||||
'value' => isset($has_frac->value),
|
||||
'scale' => isset($has_frac->scale),
|
||||
],
|
||||
]);
|
||||
echo "\n";
|
||||
|
||||
echo "========== empty ==========\n";
|
||||
var_dump([
|
||||
'zero' => [
|
||||
'value' => empty($zero->value),
|
||||
'scale' => empty($zero->scale),
|
||||
],
|
||||
'one' => [
|
||||
'value' => empty($one->value),
|
||||
'scale' => empty($one->scale),
|
||||
],
|
||||
'has_frac' => [
|
||||
'value' => empty($has_frac->value),
|
||||
'scale' => empty($has_frac->scale),
|
||||
],
|
||||
]);
|
||||
echo "\n";
|
||||
|
||||
echo "========== property_exists ==========\n";
|
||||
var_dump([
|
||||
'zero' => [
|
||||
'value' => property_exists($zero, 'value'),
|
||||
'scale' => property_exists($zero, 'scale'),
|
||||
],
|
||||
'one' => [
|
||||
'value' => property_exists($one, 'value'),
|
||||
'scale' => property_exists($one, 'scale'),
|
||||
],
|
||||
'has_frac' => [
|
||||
'value' => property_exists($has_frac, 'value'),
|
||||
'scale' => property_exists($has_frac, 'scale'),
|
||||
],
|
||||
]);
|
||||
?>
|
||||
--EXPECT--
|
||||
========== isset ==========
|
||||
array(3) {
|
||||
["zero"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
bool(true)
|
||||
["scale"]=>
|
||||
bool(true)
|
||||
}
|
||||
["one"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
bool(true)
|
||||
["scale"]=>
|
||||
bool(true)
|
||||
}
|
||||
["has_frac"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
bool(true)
|
||||
["scale"]=>
|
||||
bool(true)
|
||||
}
|
||||
}
|
||||
|
||||
========== empty ==========
|
||||
array(3) {
|
||||
["zero"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
bool(true)
|
||||
["scale"]=>
|
||||
bool(true)
|
||||
}
|
||||
["one"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
bool(false)
|
||||
["scale"]=>
|
||||
bool(true)
|
||||
}
|
||||
["has_frac"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
bool(false)
|
||||
["scale"]=>
|
||||
bool(false)
|
||||
}
|
||||
}
|
||||
|
||||
========== property_exists ==========
|
||||
array(3) {
|
||||
["zero"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
bool(true)
|
||||
["scale"]=>
|
||||
bool(true)
|
||||
}
|
||||
["one"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
bool(true)
|
||||
["scale"]=>
|
||||
bool(true)
|
||||
}
|
||||
["has_frac"]=>
|
||||
array(2) {
|
||||
["value"]=>
|
||||
bool(true)
|
||||
["scale"]=>
|
||||
bool(true)
|
||||
}
|
||||
}
|
49
ext/bcmath/tests/number/properties_read.phpt
Normal file
49
ext/bcmath/tests/number/properties_read.phpt
Normal file
|
@ -0,0 +1,49 @@
|
|||
--TEST--
|
||||
BcMath\Number properties read
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
'0',
|
||||
'0.0',
|
||||
'2',
|
||||
'1234',
|
||||
'12.0004',
|
||||
'0.1230',
|
||||
1,
|
||||
12345,
|
||||
];
|
||||
|
||||
foreach ($values as $value) {
|
||||
$num = new BcMath\Number($value);
|
||||
echo "value: {$num->value}\n";
|
||||
echo "scale: {$num->scale}\n";
|
||||
echo "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
value: 0
|
||||
scale: 0
|
||||
|
||||
value: 0.0
|
||||
scale: 1
|
||||
|
||||
value: 2
|
||||
scale: 0
|
||||
|
||||
value: 1234
|
||||
scale: 0
|
||||
|
||||
value: 12.0004
|
||||
scale: 4
|
||||
|
||||
value: 0.1230
|
||||
scale: 4
|
||||
|
||||
value: 1
|
||||
scale: 0
|
||||
|
||||
value: 12345
|
||||
scale: 0
|
36
ext/bcmath/tests/number/properties_unknown.phpt
Normal file
36
ext/bcmath/tests/number/properties_unknown.phpt
Normal file
|
@ -0,0 +1,36 @@
|
|||
--TEST--
|
||||
BcMath\Number properties unknown
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$num = new BcMath\Number(1);
|
||||
|
||||
var_dump($num->foo);
|
||||
|
||||
try {
|
||||
$num->foo = 1;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
var_dump($num->foo);
|
||||
|
||||
try {
|
||||
$num->bar = 1;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
var_dump(isset($num->foo));
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: Undefined property: BcMath\Number::$foo in %s
|
||||
NULL
|
||||
Cannot create dynamic property BcMath\Number::$foo
|
||||
|
||||
Warning: Undefined property: BcMath\Number::$foo in %s
|
||||
NULL
|
||||
Cannot create dynamic property BcMath\Number::$bar
|
||||
bool(false)
|
23
ext/bcmath/tests/number/properties_unset.phpt
Normal file
23
ext/bcmath/tests/number/properties_unset.phpt
Normal file
|
@ -0,0 +1,23 @@
|
|||
--TEST--
|
||||
BcMath\Number properties unset
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$num = new BcMath\Number(1);
|
||||
try {
|
||||
unset($num->value);
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
unset($num->scale);
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
Cannot unset readonly property BcMath\Number::$value
|
||||
Cannot unset readonly property BcMath\Number::$scale
|
23
ext/bcmath/tests/number/properties_write_error.phpt
Normal file
23
ext/bcmath/tests/number/properties_write_error.phpt
Normal file
|
@ -0,0 +1,23 @@
|
|||
--TEST--
|
||||
BcMath\Number properties write error
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$num = new BcMath\Number(1);
|
||||
try {
|
||||
$num->value = 1;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
$num->scale = 1;
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
Cannot modify readonly property BcMath\Number::$value
|
||||
Cannot modify readonly property BcMath\Number::$scale
|
32
ext/bcmath/tests/number/serialize.phpt
Normal file
32
ext/bcmath/tests/number/serialize.phpt
Normal file
|
@ -0,0 +1,32 @@
|
|||
--TEST--
|
||||
BcMath\Number serialize
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
'0',
|
||||
'0.0',
|
||||
'2',
|
||||
'1234',
|
||||
'12.0004',
|
||||
'0.1230',
|
||||
1,
|
||||
12345,
|
||||
];
|
||||
|
||||
foreach ($values as $value) {
|
||||
$num = new BcMath\Number($value);
|
||||
echo serialize($num) . "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
O:13:"BcMath\Number":1:{s:5:"value";s:1:"0";}
|
||||
O:13:"BcMath\Number":1:{s:5:"value";s:3:"0.0";}
|
||||
O:13:"BcMath\Number":1:{s:5:"value";s:1:"2";}
|
||||
O:13:"BcMath\Number":1:{s:5:"value";s:4:"1234";}
|
||||
O:13:"BcMath\Number":1:{s:5:"value";s:7:"12.0004";}
|
||||
O:13:"BcMath\Number":1:{s:5:"value";s:6:"0.1230";}
|
||||
O:13:"BcMath\Number":1:{s:5:"value";s:1:"1";}
|
||||
O:13:"BcMath\Number":1:{s:5:"value";s:5:"12345";}
|
73
ext/bcmath/tests/number/unserialize.phpt
Normal file
73
ext/bcmath/tests/number/unserialize.phpt
Normal file
|
@ -0,0 +1,73 @@
|
|||
--TEST--
|
||||
BcMath\Number unserialize
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$values = [
|
||||
'O:13:"BcMath\Number":1:{s:5:"value";s:1:"0";}',
|
||||
'O:13:"BcMath\Number":1:{s:5:"value";s:3:"0.0";}',
|
||||
'O:13:"BcMath\Number":1:{s:5:"value";s:1:"2";}',
|
||||
'O:13:"BcMath\Number":1:{s:5:"value";s:4:"1234";}',
|
||||
'O:13:"BcMath\Number":1:{s:5:"value";s:7:"12.0004";}',
|
||||
'O:13:"BcMath\Number":1:{s:5:"value";s:6:"0.1230";}',
|
||||
'O:13:"BcMath\Number":1:{s:5:"value";s:1:"1";}',
|
||||
'O:13:"BcMath\Number":1:{s:5:"value";s:5:"12345";}',
|
||||
];
|
||||
|
||||
foreach ($values as $value) {
|
||||
$num = unserialize($value);
|
||||
var_dump($num);
|
||||
unset($num);
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "0"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(3) "0.0"
|
||||
["scale"]=>
|
||||
int(1)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "2"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(4) "1234"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(7) "12.0004"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(6) "0.1230"
|
||||
["scale"]=>
|
||||
int(4)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(1) "1"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
||||
object(BcMath\Number)#1 (2) {
|
||||
["value"]=>
|
||||
string(5) "12345"
|
||||
["scale"]=>
|
||||
int(0)
|
||||
}
|
36
ext/bcmath/tests/number/unserialize_error.phpt
Normal file
36
ext/bcmath/tests/number/unserialize_error.phpt
Normal file
|
@ -0,0 +1,36 @@
|
|||
--TEST--
|
||||
BcMath\Number unserialize error
|
||||
--EXTENSIONS--
|
||||
bcmath
|
||||
--FILE--
|
||||
<?php
|
||||
try {
|
||||
$num = new BcMath\Number(1);
|
||||
$num->__unserialize(['value' => '5']);
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
$cases = [
|
||||
'O:13:"BcMath\Number":1:{s:5:"value";s:1:"a";}',
|
||||
'O:13:"BcMath\Number":1:{s:5:"value";s:0:"";}',
|
||||
'O:13:"BcMath\Number":0:{}',
|
||||
'O:13:"BcMath\Number":1:{s:5:"value";i:1;}',
|
||||
];
|
||||
|
||||
foreach ($cases as $case) {
|
||||
try {
|
||||
unserialize($case);
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
Cannot modify readonly property BcMath\Number::$value
|
||||
|
||||
Invalid serialization data for BcMath\Number object
|
||||
Invalid serialization data for BcMath\Number object
|
||||
Invalid serialization data for BcMath\Number object
|
||||
Invalid serialization data for BcMath\Number object
|
Loading…
Add table
Add a link
Reference in a new issue