diff --git a/php_decimal.c b/php_decimal.c index cbcb9c3..e297ec5 100644 --- a/php_decimal.c +++ b/php_decimal.c @@ -592,6 +592,17 @@ static void php_decimal_set_nan(php_decimal_t *obj) php_decimal_mpd_set_nan(PHP_DECIMAL_MPD(obj)); } +/** + * Sets the value to "0" in case it is "-0" + */ +static void php_decimal_prevent_negative_zero(mpd_t *mpd) +{ + if (mpd_iszero(mpd) && mpd_isnegative(mpd)) { + uint32_t status = 0; + mpd_qcopy_negate(mpd, mpd, &status); + } +} + /** * Parses a string to a given precision. Trailing zeroes are not preserved. */ @@ -617,6 +628,8 @@ static php_success_t php_decimal_mpd_set_string(mpd_t *mpd, zend_string *str, ze php_decimal_loss_of_data_on_string_conversion(); } + php_decimal_prevent_negative_zero(mpd); + return SUCCESS; } @@ -1157,12 +1170,16 @@ static void php_decimal_ceil(php_decimal_t *res, mpd_t *op1) */ static void php_decimal_truncate(php_decimal_t *res, mpd_t *op1) { + mpd_t *mpd = PHP_DECIMAL_MPD(res); uint32_t status = 0; + if (mpd_isspecial(op1)) { - mpd_qcopy(PHP_DECIMAL_MPD(res), op1, &status); + mpd_qcopy(mpd, op1, &status); return; } - mpd_qtrunc(PHP_DECIMAL_MPD(res), op1, php_decimal_context(), &status); + + mpd_qtrunc(mpd, op1, php_decimal_context(), &status); + php_decimal_prevent_negative_zero(mpd); } /** @@ -1197,6 +1214,12 @@ static void php_decimal_abs(php_decimal_t *res, mpd_t *op1) static void php_decimal_negate(php_decimal_t *res, mpd_t *op1) { uint32_t status = 0; + + if (mpd_iszero(op1)) { + mpd_qcopy(PHP_DECIMAL_MPD(res), op1, &status); + return; + } + mpd_qcopy_negate(PHP_DECIMAL_MPD(res), op1, &status); } @@ -1433,6 +1456,8 @@ static void php_decimal_do_binary_op(php_decimal_binary_op_t op, php_decimal_t * php_decimal_set_precision(res, prec); op(res, mpd1, mpd2); mpd_del(&tmp); + + php_decimal_prevent_negative_zero(PHP_DECIMAL_MPD(res)); } @@ -2201,7 +2226,10 @@ PHP_DECIMAL_METHOD(round) #endif ZEND_PARSE_PARAMETERS_END(); - php_decimal_round_mpd(PHP_DECIMAL_MPD(res), PHP_DECIMAL_MPD(obj), places, rounding); + mpd_t *mpd = PHP_DECIMAL_MPD(res); + php_decimal_round_mpd(mpd, PHP_DECIMAL_MPD(obj), places, rounding); + php_decimal_prevent_negative_zero(mpd); + RETURN_DECIMAL(res); } @@ -2376,7 +2404,7 @@ PHP_DECIMAL_METHOD(isPositive) mpd_t *mpd = THIS_MPD(); - RETURN_BOOL(!mpd_isnan(mpd) && mpd_ispositive(mpd)); + RETURN_BOOL(!mpd_isnan(mpd) && !mpd_iszero(mpd) && mpd_ispositive(mpd)); } /** @@ -2390,7 +2418,7 @@ PHP_DECIMAL_METHOD(isNegative) mpd_t *mpd = THIS_MPD(); - RETURN_BOOL(!mpd_isnan(mpd) && mpd_isnegative(mpd)); + RETURN_BOOL(!mpd_isnan(mpd) && !mpd_iszero(mpd) && mpd_isnegative(mpd)); } /** diff --git a/tests/php7/cast.phpt b/tests/php7/cast.phpt index bb42d28..79e6986 100644 --- a/tests/php7/cast.phpt +++ b/tests/php7/cast.phpt @@ -19,7 +19,7 @@ $tests = [ * STRING */ [(string) decimal(), "0"], - [(string) decimal("-0"), "-0"], + [(string) decimal("-0"), "0"], [(string) decimal("5.2"), "5.2"], [(string) decimal( "NAN"), "NAN"], diff --git a/tests/php7/clone.phpt b/tests/php7/clone.phpt index 43ec8e9..eaa85e1 100644 --- a/tests/php7/clone.phpt +++ b/tests/php7/clone.phpt @@ -11,6 +11,12 @@ use Decimal\Decimal; $a = new Decimal("1.234", 16); $b = clone $a; +var_dump($a); +var_dump($b); + +$a = new Decimal("-0"); +$b = clone $a; + var_dump($a); var_dump($b); ?> @@ -27,3 +33,15 @@ object(Decimal\Decimal)#2 (2) { ["precision"]=> int(16) } +object(Decimal\Decimal)#3 (2) { + ["value"]=> + string(1) "0" + ["precision"]=> + int(28) +} +object(Decimal\Decimal)#1 (2) { + ["value"]=> + string(1) "0" + ["precision"]=> + int(28) +} diff --git a/tests/php7/empty.phpt b/tests/php7/empty.phpt index e5a94fc..5d41d9d 100644 --- a/tests/php7/empty.phpt +++ b/tests/php7/empty.phpt @@ -10,6 +10,7 @@ use Decimal\Decimal; var_dump(empty(new Decimal())); var_dump(empty(new Decimal(0))); +var_dump(empty(new Decimal('-0'))); var_dump(empty(new Decimal(1))); var_dump(empty(new Decimal( "1E-1000"))); @@ -28,3 +29,4 @@ bool(false) bool(false) bool(false) bool(false) +bool(false) diff --git a/tests/php7/json.phpt b/tests/php7/json.phpt index d570c72..0e11610 100644 --- a/tests/php7/json.phpt +++ b/tests/php7/json.phpt @@ -9,9 +9,11 @@ if (!extension_loaded("json")) echo 'skip'; --EXPECT-- +string(3) ""0"" string(8) ""1.2345"" string(8) ""5.0000"" diff --git a/tests/php7/methods/abs.phpt b/tests/php7/methods/abs.phpt index 8a7fe76..4948f45 100644 --- a/tests/php7/methods/abs.phpt +++ b/tests/php7/methods/abs.phpt @@ -14,6 +14,9 @@ use Decimal\Decimal; function decimal(...$args) { return new Decimal(...$args); } $tests = [ + ["0", "0"], + ["-0", "0"], + ["-0.1", "0.1"], ["+0.1", "0.1"], [ "0.1", "0.1"], diff --git a/tests/php7/methods/avg.phpt b/tests/php7/methods/avg.phpt index 41f390f..74f22c0 100644 --- a/tests/php7/methods/avg.phpt +++ b/tests/php7/methods/avg.phpt @@ -39,6 +39,9 @@ $tests = [ [[array('-2.3', '4.1', 5), ], "2.266666666666666666666666667", 28], [[array('-2.3', '4.1', 5), 10], "2.266666667", 10], [[array('-2.3', '4.1', 5), 30], "2.26666666666666666666666666667", 30], + + [[[decimal("0.1"), decimal("-0.1")]], "0.0", 28], + [[[decimal("-0.1"), decimal("0.1")]], "0.0", 28], ]; foreach ($tests as $index => $test) { diff --git a/tests/php7/methods/ceil.phpt b/tests/php7/methods/ceil.phpt index b932162..4b0d082 100644 --- a/tests/php7/methods/ceil.phpt +++ b/tests/php7/methods/ceil.phpt @@ -14,6 +14,9 @@ use Decimal\Decimal; function decimal(...$args) { return new Decimal(...$args); } $tests = [ + ["0", "0"], + ["-0", "0"], + ["-0.1", "-0"], [ "0.1", "1"], diff --git a/tests/php7/methods/compareTo.phpt b/tests/php7/methods/compareTo.phpt index f1da14a..0e3cbff 100644 --- a/tests/php7/methods/compareTo.phpt +++ b/tests/php7/methods/compareTo.phpt @@ -29,6 +29,11 @@ $tests = [ [decimal(), false, 1], [decimal(), 0.0, 0], + [decimal("-0"), 0, 0], + [decimal("-0"), null, 1], + [decimal("-0"), false, 1], + [decimal("-0"), 0.0, 0], + [decimal(1), 0, 1], [decimal(1), null, 1], [decimal(1), false, 1], diff --git a/tests/php7/methods/copy.phpt b/tests/php7/methods/copy.phpt index e7322c0..0156a63 100644 --- a/tests/php7/methods/copy.phpt +++ b/tests/php7/methods/copy.phpt @@ -11,6 +11,11 @@ $dst = $src->copy(); var_dump($src, $dst); +$src = new Decimal\Decimal("-0", 32); +$dst = $src->copy(); + +var_dump($src, $dst); + ?> --EXPECT-- object(Decimal\Decimal)#1 (2) { @@ -25,3 +30,15 @@ object(Decimal\Decimal)#2 (2) { ["precision"]=> int(32) } +object(Decimal\Decimal)#3 (2) { + ["value"]=> + string(1) "0" + ["precision"]=> + int(32) +} +object(Decimal\Decimal)#1 (2) { + ["value"]=> + string(1) "0" + ["precision"]=> + int(32) +} diff --git a/tests/php7/methods/div.phpt b/tests/php7/methods/div.phpt index 748922d..40787c4 100644 --- a/tests/php7/methods/div.phpt +++ b/tests/php7/methods/div.phpt @@ -65,6 +65,17 @@ $tests = [ [new Decimal("-INF"), "NAN", (string) (-INF / NAN), 28], [new Decimal("-INF"), "INF", (string) (-INF / INF), 28], [new Decimal("-INF"), "-INF", (string) (-INF / -INF), 28], + + [ + new Decimal("0"), + new Decimal("10"), + "0", 28 + ], + [ + new Decimal("-0"), + new Decimal("10"), + "0", 28 + ], ]; foreach ($tests as $index => $test) { diff --git a/tests/php7/methods/equals.phpt b/tests/php7/methods/equals.phpt index 03d82cc..aec7c24 100644 --- a/tests/php7/methods/equals.phpt +++ b/tests/php7/methods/equals.phpt @@ -36,6 +36,8 @@ $tests = [ [decimal(1), 1.0, true], [decimal(1), "1", true], + [decimal("-0"), 0, true], + [decimal("0.1"), 0.1, true], [decimal("0.2"), 0.2, true], [decimal("0.200"), 0.2, true], diff --git a/tests/php7/methods/exp.phpt b/tests/php7/methods/exp.phpt index 53d8f6e..e2c8e4a 100644 --- a/tests/php7/methods/exp.phpt +++ b/tests/php7/methods/exp.phpt @@ -14,6 +14,9 @@ use Decimal\Decimal; function decimal(...$args) { return new Decimal(...$args); } $tests = [ + [decimal("0"), "1", 28], + [decimal("-0"), "1", 28], + [decimal("-0.1", 50), "0.90483741803595957316424905944643662119470536098040", 50], [decimal( "0.1", 50), "1.1051709180756476248117078264902466682245471947375", 50], diff --git a/tests/php7/methods/floor.phpt b/tests/php7/methods/floor.phpt index 1156032..392d047 100644 --- a/tests/php7/methods/floor.phpt +++ b/tests/php7/methods/floor.phpt @@ -14,6 +14,9 @@ use Decimal\Decimal; function decimal(...$args) { return new Decimal(...$args); } $tests = [ + ["0", "0"], + ["-0", "0"], + ["-0.1", "-1"], [ "0.1", "0"], diff --git a/tests/php7/methods/isEven.phpt b/tests/php7/methods/isEven.phpt index 3bddc8f..be2bb17 100644 --- a/tests/php7/methods/isEven.phpt +++ b/tests/php7/methods/isEven.phpt @@ -20,6 +20,7 @@ $tests = [ ["-2.000000000000000000000000001", false], // not truncated [0, true], + ["-0", true], [1, false], [2, true], [3, false], diff --git a/tests/php7/methods/isInf.phpt b/tests/php7/methods/isInf.phpt index 4a58d06..c7f037f 100644 --- a/tests/php7/methods/isInf.phpt +++ b/tests/php7/methods/isInf.phpt @@ -20,6 +20,7 @@ $tests = [ ["-1E-50", false], [0, false], + ["-0", false], [1, false], [2, false], [3, false], diff --git a/tests/php7/methods/isInteger.phpt b/tests/php7/methods/isInteger.phpt index 93e713f..cc432c2 100644 --- a/tests/php7/methods/isInteger.phpt +++ b/tests/php7/methods/isInteger.phpt @@ -20,6 +20,7 @@ $tests = [ ["-1E-50", false], [0, true], + ["-0", true], [1, true], [2, true], [3, true], diff --git a/tests/php7/methods/isNaN.phpt b/tests/php7/methods/isNaN.phpt index 82c3967..6be6a7c 100644 --- a/tests/php7/methods/isNaN.phpt +++ b/tests/php7/methods/isNaN.phpt @@ -20,6 +20,7 @@ $tests = [ ["-1E-50", false], [0, false], + ["-0", false], [1, false], [2, false], [3, false], diff --git a/tests/php7/methods/isNegative.phpt b/tests/php7/methods/isNegative.phpt index b181342..cb55de1 100644 --- a/tests/php7/methods/isNegative.phpt +++ b/tests/php7/methods/isNegative.phpt @@ -20,7 +20,7 @@ $tests = [ ["-1E-50", true], ["0", false], - ["-0", true], + ["-0", false], [1, false], [2, false], [3, false], diff --git a/tests/php7/methods/isOdd.phpt b/tests/php7/methods/isOdd.phpt index f64093c..0068d93 100644 --- a/tests/php7/methods/isOdd.phpt +++ b/tests/php7/methods/isOdd.phpt @@ -20,6 +20,7 @@ $tests = [ ["-3.000000000000000000000000001", false], // not truncated [0, false], + ["-0", false], [1, true], [2, false], [3, true], diff --git a/tests/php7/methods/isPositive.phpt b/tests/php7/methods/isPositive.phpt index 96e0fc2..6a968d7 100644 --- a/tests/php7/methods/isPositive.phpt +++ b/tests/php7/methods/isPositive.phpt @@ -19,7 +19,7 @@ $tests = [ [ "1E-50", true], ["-1E-50", false], - ["0", true], + ["0", false], ["-0", false], [1, true], [2, true], diff --git a/tests/php7/methods/isZero.phpt b/tests/php7/methods/isZero.phpt index d27abe4..370e87b 100644 --- a/tests/php7/methods/isZero.phpt +++ b/tests/php7/methods/isZero.phpt @@ -20,6 +20,7 @@ $tests = [ ["-1E-50", false], [0, true], + ["-0", true], [1, false], [2, false], [3, false], diff --git a/tests/php7/methods/ln.phpt b/tests/php7/methods/ln.phpt index 29292a7..6ff1410 100644 --- a/tests/php7/methods/ln.phpt +++ b/tests/php7/methods/ln.phpt @@ -40,6 +40,7 @@ $tests = [ [decimal( "NAN"), (string) log( NAN), 28], [decimal( "INF"), (string) log( INF), 28], [decimal( "0"), (string) log( 0), 28], + [decimal( "-0"), (string) log( 0), 28], [decimal( "-1"), (string) log( -1), 28], ]; diff --git a/tests/php7/methods/log10.phpt b/tests/php7/methods/log10.phpt index c92bb22..8c4694c 100644 --- a/tests/php7/methods/log10.phpt +++ b/tests/php7/methods/log10.phpt @@ -40,6 +40,7 @@ $tests = [ [decimal( "NAN"), (string) log10( NAN), 28], [decimal( "INF"), (string) log10( INF), 28], [decimal( "0"), (string) log10( 0), 28], + [decimal( "-0"), (string) log10( 0), 28], [decimal( "-1"), (string) log10( -1), 28], ]; diff --git a/tests/php7/methods/mod.phpt b/tests/php7/methods/mod.phpt index 4866915..8734344 100644 --- a/tests/php7/methods/mod.phpt +++ b/tests/php7/methods/mod.phpt @@ -19,6 +19,8 @@ function decimal(...$args) { return new Decimal(...$args); } $tests = [ [decimal("0"), "1", 0 % 1, 28], [decimal("0"), "-1", 0 % -1, 28], + [decimal("-0"), "1", 0 % 1, 28], + [decimal("-0"), "-1", 0 % -1, 28], [decimal( "1"), "3", 1 % 3, 28], [decimal( "1"), "-3", 1 % -3, 28], diff --git a/tests/php7/methods/mul.phpt b/tests/php7/methods/mul.phpt index 8577034..c2af5ee 100644 --- a/tests/php7/methods/mul.phpt +++ b/tests/php7/methods/mul.phpt @@ -75,6 +75,9 @@ $tests = [ [new Decimal( "NAN"), 0, "NAN", 28], [new Decimal( "INF"), 0, "NAN", 28], [new Decimal("-INF"), 0, "NAN", 28], + + [new Decimal("0"), 2, "0", 28], + [new Decimal("-0"), 2, "0", 28], ]; foreach ($tests as $index => $test) { @@ -122,8 +125,8 @@ Warning: Loss of data on string conversion in %s on line 24 Warning: Loss of data on string conversion in %s on line 25 -Warning: Loss of data on integer conversion in %s on line 77 +Warning: Loss of data on integer conversion in %s on line 80 -Warning: Loss of data on integer conversion in %s on line 79 +Warning: Loss of data on integer conversion in %s on line 82 -Warning: Loss of data on integer conversion in %s on line 80 +Warning: Loss of data on integer conversion in %s on line 83 diff --git a/tests/php7/methods/negate.phpt b/tests/php7/methods/negate.phpt index 0af2b21..e5c5f60 100644 --- a/tests/php7/methods/negate.phpt +++ b/tests/php7/methods/negate.phpt @@ -34,9 +34,9 @@ var_dump((string) $obj); ?> --EXPECT-- -string(2) "-0" string(1) "0" -string(2) "-0" +string(1) "0" +string(1) "0" string(2) "-1" string(1) "1" string(3) "NAN" diff --git a/tests/php7/methods/pow.phpt b/tests/php7/methods/pow.phpt index 14d7ac9..7dba45b 100644 --- a/tests/php7/methods/pow.phpt +++ b/tests/php7/methods/pow.phpt @@ -23,6 +23,8 @@ $tests = [ [decimal("0"), "0", pow(0, 0)], [decimal("0"), "1", pow(0, 1)], + [decimal("-0"), "0", pow(0, 0)], + [decimal("-0"), "1", pow(0, 1)], [decimal("1"), "-2", pow(1, -2)], [decimal("1"), "-1", pow(1, -1)], diff --git a/tests/php7/methods/rem.phpt b/tests/php7/methods/rem.phpt index 068ba63..7fab407 100644 --- a/tests/php7/methods/rem.phpt +++ b/tests/php7/methods/rem.phpt @@ -19,6 +19,8 @@ function decimal(...$args) { return new Decimal(...$args); } $tests = [ [decimal("0"), "1", 0 % 1, 28], [decimal("0"), "-1", 0 % -1, 28], + [decimal("-0"), "1", 0 % 1, 28], + [decimal("-0"), "-1", 0 % -1, 28], [decimal( "1"), "3", 1 % 3, 28], [decimal( "1"), "-3", 1 % -3, 28], diff --git a/tests/php7/methods/round.phpt b/tests/php7/methods/round.phpt index 2164516..0045b4a 100644 --- a/tests/php7/methods/round.phpt +++ b/tests/php7/methods/round.phpt @@ -298,6 +298,10 @@ $tests = [ ["123.45", 10, [Decimal::ROUND_HALF_UP], "123.45"], ["1234.5", 10, [Decimal::ROUND_HALF_UP], "1234.5"], ["12345", 10, [Decimal::ROUND_HALF_UP], "12345"], + + /* NEGATIVE VALUE TO ZERO */ + ["-0.1", 0, [Decimal::ROUND_HALF_UP], "0"], + ["-0.000001", 3, [Decimal::ROUND_HALF_UP], "0.000"], ]; foreach ($tests as $test) { diff --git a/tests/php7/methods/shift.phpt b/tests/php7/methods/shift.phpt index 14c01ff..5e05429 100644 --- a/tests/php7/methods/shift.phpt +++ b/tests/php7/methods/shift.phpt @@ -16,6 +16,9 @@ function decimal(...$args) { return new Decimal(...$args); } $tests = [ /* A * B = C */ + ["0", -3, "0.000"], + ["-0", -3, "0.000"], + ["1", -3, "0.001"], ["1", -2, "0.01"], ["1", -1, "0.1"], diff --git a/tests/php7/methods/sqrt.phpt b/tests/php7/methods/sqrt.phpt index 5e3a5a4..297930b 100644 --- a/tests/php7/methods/sqrt.phpt +++ b/tests/php7/methods/sqrt.phpt @@ -15,6 +15,9 @@ function decimal(...$args) { return new Decimal(...$args); } $tests = [ [decimal(), "0", 28], + [decimal("0"), "0", 28], + [decimal("-0"), "0", 28], + [decimal("0.1", 5), "0.31623", 5], [decimal("0.1"), "0.3162277660168379331998893544", 28], [decimal("0.1", 50), "0.31622776601683793319988935444327185337195551393252", 50], diff --git a/tests/php7/methods/sum.phpt b/tests/php7/methods/sum.phpt index 28bea71..d28def1 100644 --- a/tests/php7/methods/sum.phpt +++ b/tests/php7/methods/sum.phpt @@ -39,6 +39,9 @@ $tests = [ [[array('-2.3', '4.1'), ], "1.8", 28], [[array('-2.3', '4.1'), 10], "1.8", 10], [[array('-2.3', '4.1'), 30], "1.8", 30], + + [[[decimal("0.1"), decimal("-0.1")]], "0.0", 28], + [[[decimal("-0.1"), decimal("0.1")]], "0.0", 28], ]; foreach ($tests as $index => $test) { diff --git a/tests/php7/methods/toFixed.phpt b/tests/php7/methods/toFixed.phpt index 9b1d6f9..baa8f87 100644 --- a/tests/php7/methods/toFixed.phpt +++ b/tests/php7/methods/toFixed.phpt @@ -12,6 +12,7 @@ $tests = [ /* decimal places, grouped, rounding mode, expected */ ["0", 5, false, Decimal::ROUND_HALF_UP, "0.00000"], + ["-0", 5, false, Decimal::ROUND_HALF_UP, "0.00000"], ["1.23456", 3, false, Decimal::ROUND_UP, "1.235"], ["1.23456", 3, false, Decimal::ROUND_DOWN, "1.234"], diff --git a/tests/php7/methods/toFloat.phpt b/tests/php7/methods/toFloat.phpt index 6661f17..90f9397 100644 --- a/tests/php7/methods/toFloat.phpt +++ b/tests/php7/methods/toFloat.phpt @@ -16,6 +16,7 @@ function decimal(...$args) { return new Decimal(...$args); } $tests = [ ["0", 0.0], + ["-0", 0.0], ["-0.1", -0.1], [ "0.1", 0.1], diff --git a/tests/php7/methods/toInt.phpt b/tests/php7/methods/toInt.phpt index bcf663a..45769c1 100644 --- a/tests/php7/methods/toInt.phpt +++ b/tests/php7/methods/toInt.phpt @@ -15,6 +15,7 @@ function decimal(...$args) { return new Decimal(...$args); } $tests = [ ["0", 0], + ["-0", 0], ["-0.1", 0], [ "0.1", 0], diff --git a/tests/php7/methods/toString.phpt b/tests/php7/methods/toString.phpt index 1e7e069..ed15138 100644 --- a/tests/php7/methods/toString.phpt +++ b/tests/php7/methods/toString.phpt @@ -17,7 +17,7 @@ $tests = [ [0, "0"], ["0", "0"], ["+0", "0"], - ["-0", "-0"], + ["-0", "0"], ["0.0", "0.0"], ["1", "1"], ["1.5", "1.5"], diff --git a/tests/php7/methods/truncate.phpt b/tests/php7/methods/truncate.phpt index 5844f98..a9ab8bd 100644 --- a/tests/php7/methods/truncate.phpt +++ b/tests/php7/methods/truncate.phpt @@ -23,6 +23,8 @@ var_dump((string) decimal( "NAN")->truncate()); var_dump((string) decimal( "INF")->truncate()); var_dump((string) decimal("-INF")->truncate()); +var_dump((string) decimal("-0.1")->truncate()); + /** * Check that truncate does not modify the original */ @@ -38,4 +40,5 @@ string(1) "0" string(3) "NAN" string(3) "INF" string(4) "-INF" +string(1) "0" string(5) "1.234" diff --git a/tests/php7/serialize.phpt b/tests/php7/serialize.phpt index 9470430..72b5d7b 100644 --- a/tests/php7/serialize.phpt +++ b/tests/php7/serialize.phpt @@ -10,6 +10,11 @@ use Decimal\Decimal; $decimal = new Decimal("1234.5678E+9", 42); +var_dump(serialize($decimal)); +var_dump(unserialize(serialize($decimal))); + +$decimal = new Decimal("-0"); + var_dump(serialize($decimal)); var_dump(unserialize(serialize($decimal))); ?> @@ -21,3 +26,10 @@ object(Decimal\Decimal)#2 (2) { ["precision"]=> int(42) } +string(41) "C:15:"Decimal\Decimal":13:{s:1:"0";i:28;}" +object(Decimal\Decimal)#1 (2) { + ["value"]=> + string(1) "0" + ["precision"]=> + int(28) +}