Skip to content

Commit 57aee69

Browse files
rudi-augmentclaude
andcommitted
Rename toSci to toScientific, add missing tests, update package.xml
- Rename toSci method to toScientific on Decimal, Rational, and Number - Add tests for Decimal::isPositive, Decimal::isNegative - Add tests for Rational::isPositive, Rational::isNegative - Add test for Rational::trunc - Add test for Rational::toScientific - Update package.xml with all test files and release notes - Update CHANGELOG.md for v2.0.0 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f9d8906 commit 57aee69

12 files changed

Lines changed: 360 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22
All notable changes to this project will be documented in this file.
33
This project follows [Semantic Versioning](http://semver.org/).
44

5-
## [2.0.0] - 2020-02-03
5+
## [2.0.0] - 2026-04-11
66
- Default decimal precision changed from 28 to 34 to match [Decimal128](https://en.wikipedia.org/wiki/Decimal128_floating-point_format).
77
- Decimal operations now use the **minimum** precision of all operands, rather than the maximum.
8-
- Remove `Decimal\Decimal::equals` method.
98
- Added `Decimal\Rational` implementation for rational numbers (fractions).
109
- Added `Decimal\Number` abstract number class.
1110
- Added `Decimal\Precision` interface.
1211
- Added `Decimal\Decimal::reduce` method.
12+
- Renamed `toSci` to `toScientific`.
1313
- Remove `signum` methods.
1414
- Remove `parity` methods.
1515
- Better consistency around scientific notation when converting to string or JSON.
1616
- Precision is now applied on operations only (input is preserved).
1717
- Decimal constructors are now private - must use `\Decimal\Number::valueOf`.
18+
- Performance improvements, reduced object allocations.
19+
- PHP 8.2, 8.3, and 8.4 compatibility.
20+
- Fixed `isPositive`/`isNegative` to return false for zero values.
21+
- Fixed array/debug output for Decimal and Rational objects.
1822

1923
## [1.3.0] - 2019-02-11
2024
- Fixed sqrt of -INF returning -INF rather than NAN. #13

package.xml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<email>rtheunissen@php.net</email>
1111
<active>yes</active>
1212
</lead>
13-
<date>2026-04-09</date>
13+
<date>2026-04-11</date>
1414
<time>00:00:00</time>
1515
<version>
1616
<release>2.0.0</release>
@@ -28,15 +28,17 @@
2828
- Added `Decimal\Number` abstract class.
2929
- Performance improvements, reduced object allocations.
3030
- Private constructors, static initializers via `valueOf`.
31-
- PHP 8.2+ compatibility.
31+
- PHP 8.2, 8.3, and 8.4 compatibility.
3232
- Fixed isPositive/isNegative to return false for zero values.
3333
- Fixed array/debug output for Decimal and Rational objects.
34+
- Renamed `toSci` to `toScientific`.
3435
</notes>
3536
<contents>
3637
<dir name="/">
3738
<file role="doc" name="LICENSE"/>
3839
<file role="doc" name="CHANGELOG.md"/>
3940
<file role="doc" name="README.md"/>
41+
<file role="doc" name="composer.json"/>
4042

4143
<file role="src" name="config.m4"/>
4244
<file role="src" name="config.w32"/>
@@ -76,6 +78,8 @@
7678
</dir>
7779

7880
<dir name="tests">
81+
<file role="test" name="opcache.phpt"/>
82+
7983
<dir name="Decimal">
8084
<file role="test" name="cast.phpt"/>
8185
<file role="test" name="clone.phpt"/>
@@ -84,22 +88,27 @@
8488
<file role="test" name="json.phpt"/>
8589
<file role="test" name="operators.phpt"/>
8690
<file role="test" name="properties.phpt"/>
91+
<file role="test" name="refcount.phpt"/>
8792
<file role="test" name="serialize.phpt"/>
8893

8994
<dir name="methods">
9095
<file role="test" name="__construct.phpt"/>
9196
<file role="test" name="abs.phpt"/>
9297
<file role="test" name="add.phpt"/>
98+
<file role="test" name="between.phpt"/>
9399
<file role="test" name="ceil.phpt"/>
94100
<file role="test" name="compareTo.phpt"/>
95101
<file role="test" name="div.phpt"/>
102+
<file role="test" name="equals.phpt"/>
96103
<file role="test" name="exp.phpt"/>
97104
<file role="test" name="floor.phpt"/>
98105
<file role="test" name="isEven.phpt"/>
99106
<file role="test" name="isInf.phpt"/>
100107
<file role="test" name="isInteger.phpt"/>
101108
<file role="test" name="isNaN.phpt"/>
109+
<file role="test" name="isNegative.phpt"/>
102110
<file role="test" name="isOdd.phpt"/>
111+
<file role="test" name="isPositive.phpt"/>
103112
<file role="test" name="isZero.phpt"/>
104113
<file role="test" name="ln.phpt"/>
105114
<file role="test" name="log10.phpt"/>
@@ -120,6 +129,7 @@
120129
<file role="test" name="toFloat.phpt"/>
121130
<file role="test" name="toInt.phpt"/>
122131
<file role="test" name="toRational.phpt"/>
132+
<file role="test" name="toScientific.phpt"/>
123133
<file role="test" name="toString.phpt"/>
124134
<file role="test" name="trim.phpt"/>
125135
<file role="test" name="trunc.phpt"/>
@@ -137,16 +147,33 @@
137147
<file role="test" name="properties.phpt"/>
138148

139149
<dir name="methods">
150+
<file role="test" name="abs.phpt"/>
140151
<file role="test" name="add.phpt"/>
152+
<file role="test" name="between.phpt"/>
153+
<file role="test" name="ceil.phpt"/>
141154
<file role="test" name="compareTo.phpt"/>
142155
<file role="test" name="div.phpt"/>
156+
<file role="test" name="equals.phpt"/>
157+
<file role="test" name="floor.phpt"/>
158+
<file role="test" name="isEven.phpt"/>
159+
<file role="test" name="isInf.phpt"/>
160+
<file role="test" name="isInteger.phpt"/>
161+
<file role="test" name="isNan.phpt"/>
162+
<file role="test" name="isNegative.phpt"/>
163+
<file role="test" name="isOdd.phpt"/>
164+
<file role="test" name="isPositive.phpt"/>
165+
<file role="test" name="isZero.phpt"/>
143166
<file role="test" name="mod.phpt"/>
144167
<file role="test" name="mul.phpt"/>
168+
<file role="test" name="negate.phpt"/>
145169
<file role="test" name="pow.phpt"/>
146170
<file role="test" name="shiftl.phpt"/>
147171
<file role="test" name="shiftr.phpt"/>
148172
<file role="test" name="sub.phpt"/>
173+
<file role="test" name="toDecimal.phpt"/>
174+
<file role="test" name="toRational.phpt"/>
149175
<file role="test" name="toString.phpt"/>
176+
<file role="test" name="trunc.phpt"/>
150177
<file role="test" name="valueOf.phpt"/>
151178
</dir>
152179

@@ -163,21 +190,26 @@
163190
<file role="test" name="json.phpt"/>
164191
<file role="test" name="operators.phpt"/>
165192
<file role="test" name="properties.phpt"/>
193+
<file role="test" name="refcount.phpt"/>
166194
<file role="test" name="serialize.phpt"/>
167195

168196
<dir name="methods">
169197
<file role="test" name="__construct.phpt"/>
170198
<file role="test" name="abs.phpt"/>
171199
<file role="test" name="add.phpt"/>
200+
<file role="test" name="between.phpt"/>
172201
<file role="test" name="ceil.phpt"/>
173202
<file role="test" name="compareTo.phpt"/>
174203
<file role="test" name="div.phpt"/>
204+
<file role="test" name="equals.phpt"/>
175205
<file role="test" name="floor.phpt"/>
176206
<file role="test" name="isEven.phpt"/>
177207
<file role="test" name="isInf.phpt"/>
178208
<file role="test" name="isInteger.phpt"/>
179209
<file role="test" name="isNaN.phpt"/>
210+
<file role="test" name="isNegative.phpt"/>
180211
<file role="test" name="isOdd.phpt"/>
212+
<file role="test" name="isPositive.phpt"/>
181213
<file role="test" name="isZero.phpt"/>
182214
<file role="test" name="mod.phpt"/>
183215
<file role="test" name="mul.phpt"/>
@@ -193,7 +225,9 @@
193225
<file role="test" name="toFloat.phpt"/>
194226
<file role="test" name="toInt.phpt"/>
195227
<file role="test" name="toRational.phpt"/>
228+
<file role="test" name="toScientific.phpt"/>
196229
<file role="test" name="toString.phpt"/>
230+
<file role="test" name="trunc.phpt"/>
197231
<file role="test" name="valueOf.phpt"/>
198232
</dir>
199233
</dir>

src/decimal.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -883,12 +883,12 @@ PHP_DECIMAL_METHOD(Decimal, toString)
883883
}
884884

885885
/**
886-
* Decimal::toSci
886+
* Decimal::toScientific
887887
*/
888-
PHP_DECIMAL_ARGINFO_RETURN_TYPE(Decimal, toSci, IS_STRING, 0)
888+
PHP_DECIMAL_ARGINFO_RETURN_TYPE(Decimal, toScientific, IS_STRING, 0)
889889
PHP_DECIMAL_ARGINFO_OPTIONAL_LONG(precision)
890890
PHP_DECIMAL_ARGINFO_END()
891-
PHP_DECIMAL_METHOD(Decimal, toSci)
891+
PHP_DECIMAL_METHOD(Decimal, toScientific)
892892
{
893893
PHP_DECIMAL_PARSE_PARAMS_NONE();
894894
RETURN_STR(php_decimal_mpd_to_sci(THIS_DECIMAL_MPD()));
@@ -1124,7 +1124,7 @@ static zend_function_entry decimal_methods[] = {
11241124

11251125
PHP_DECIMAL_ME(Decimal, toString)
11261126
PHP_DECIMAL_ME(Decimal, toFixed)
1127-
PHP_DECIMAL_ME(Decimal, toSci)
1127+
PHP_DECIMAL_ME(Decimal, toScientific)
11281128
PHP_DECIMAL_ME(Decimal, toInt)
11291129
PHP_DECIMAL_ME(Decimal, toFloat)
11301130
PHP_DECIMAL_ME(Decimal, toDecimal)

src/number.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ PHP_DECIMAL_ARGINFO_END()
469469

470470
/**
471471
* Number::ToSci
472-
PHP_DECIMAL_ARGINFO_RETURN_TYPE(Number, toSci, IS_STRING, 0)
472+
PHP_DECIMAL_ARGINFO_RETURN_TYPE(Number, toScientific, IS_STRING, 0)
473473
PHP_DECIMAL_ARGINFO_END()
474474
*/
475475

src/rational.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -808,12 +808,12 @@ PHP_DECIMAL_METHOD(Rational, toFixed)
808808
}
809809

810810
/**
811-
* Rational::toSci
811+
* Rational::toScientific
812812
*/
813-
PHP_DECIMAL_ARGINFO_RETURN_TYPE(Rational, toSci, IS_STRING, 0)
813+
PHP_DECIMAL_ARGINFO_RETURN_TYPE(Rational, toScientific, IS_STRING, 0)
814814
PHP_DECIMAL_ARGINFO_OPTIONAL_LONG(precision)
815815
PHP_DECIMAL_ARGINFO_END()
816-
PHP_DECIMAL_METHOD(Rational, toSci)
816+
PHP_DECIMAL_METHOD(Rational, toScientific)
817817
{
818818
zend_long prec = PHP_DECIMAL_DEFAULT_PREC;
819819

@@ -1050,7 +1050,7 @@ static zend_function_entry rational_methods[] = {
10501050
PHP_DECIMAL_ME(Rational, isZero)
10511051

10521052
PHP_DECIMAL_ME(Rational, toFixed)
1053-
PHP_DECIMAL_ME(Rational, toSci)
1053+
PHP_DECIMAL_ME(Rational, toScientific)
10541054
PHP_DECIMAL_ME(Rational, toString)
10551055
PHP_DECIMAL_ME(Rational, toInt)
10561056
PHP_DECIMAL_ME(Rational, toFloat)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
--TEST--
2+
Decimal::isNegative
3+
--FILE--
4+
<?php
5+
use Decimal\Decimal;
6+
7+
/**
8+
* op1, expected result
9+
*/
10+
$tests = [
11+
[ "1E-50", false],
12+
["-1E-50", true],
13+
14+
[0, false],
15+
[1, false],
16+
[2, false],
17+
[3, false],
18+
19+
[-1, true],
20+
[-2, true],
21+
[-3, true],
22+
23+
["0", false],
24+
["-0", false],
25+
26+
["0.4", false],
27+
["1.4", false],
28+
29+
["-0.4", true],
30+
["-1.4", true],
31+
32+
[ "NAN", false],
33+
[ "INF", false],
34+
["-INF", true],
35+
];
36+
37+
foreach ($tests as $test) {
38+
$number = $test[0];
39+
$expect = $test[1];
40+
$result = Decimal::valueOf($number)->isNegative();
41+
42+
if ($result !== $expect) {
43+
print_r(compact("number", "result", "expect"));
44+
}
45+
}
46+
47+
/* Zero is neither positive nor negative */
48+
var_dump(Decimal::valueOf("0")->isNegative());
49+
var_dump(Decimal::valueOf("-0")->isNegative());
50+
var_dump(Decimal::valueOf("-0.05")->trunc()->isNegative());
51+
?>
52+
--EXPECT--
53+
bool(false)
54+
bool(false)
55+
bool(false)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
--TEST--
2+
Decimal::isPositive
3+
--FILE--
4+
<?php
5+
use Decimal\Decimal;
6+
7+
/**
8+
* op1, expected result
9+
*/
10+
$tests = [
11+
[ "1E-50", true],
12+
["-1E-50", false],
13+
14+
[0, false],
15+
[1, true],
16+
[2, true],
17+
[3, true],
18+
19+
[-1, false],
20+
[-2, false],
21+
[-3, false],
22+
23+
["0", false],
24+
["-0", false],
25+
26+
["0.4", true],
27+
["1.4", true],
28+
29+
["-0.4", false],
30+
["-1.4", false],
31+
32+
[ "NAN", false],
33+
[ "INF", true],
34+
["-INF", false],
35+
];
36+
37+
foreach ($tests as $test) {
38+
$number = $test[0];
39+
$expect = $test[1];
40+
$result = Decimal::valueOf($number)->isPositive();
41+
42+
if ($result !== $expect) {
43+
print_r(compact("number", "result", "expect"));
44+
}
45+
}
46+
47+
/* Zero is neither positive nor negative */
48+
var_dump(Decimal::valueOf("0")->isPositive());
49+
var_dump(Decimal::valueOf("-0")->isPositive());
50+
var_dump(Decimal::valueOf("-0.05")->trunc()->isPositive());
51+
?>
52+
--EXPECT--
53+
bool(false)
54+
bool(false)
55+
bool(false)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Decimal::toString
2+
Decimal::toScientific
33
--FILE--
44
<?php
55
use Decimal\Decimal;
@@ -85,7 +85,7 @@ $tests = [
8585
foreach ($tests as $test) {
8686
$number = $test[0];
8787
$expect = $test[1];
88-
$result = Decimal::valueOf($number)->toSci();
88+
$result = Decimal::valueOf($number)->toScientific();
8989

9090
if ($result !== $expect) {
9191
print_r(compact("number", "result", "expect"));

0 commit comments

Comments
 (0)