File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 1515
1616use function array_shift ;
1717use function assert ;
18+ use function filter_var ;
1819use function is_float ;
1920use function is_int ;
2021use function ltrim ;
2122use function preg_match ;
2223use function str_contains ;
2324use function str_repeat ;
2425use function strlen ;
26+ use function substr ;
27+
28+ use const FILTER_VALIDATE_INT ;
2529
2630use const PHP_INT_MAX ;
2731use const PHP_INT_MIN ;
@@ -503,9 +507,23 @@ private static function _of(BigNumber|int|float|string $value): BigNumber
503507
504508 if ($ point !== null || $ exponent !== null ) {
505509 $ fractional ??= '' ;
506- $ exponent = ($ exponent !== null ) ? (int ) $ exponent : 0 ;
507510
508- if ($ exponent === PHP_INT_MIN || $ exponent === PHP_INT_MAX ) {
511+ if ($ exponent !== null ) {
512+ if (substr ($ exponent , 0 , 1 ) === '- ' ) {
513+ $ exponent = ltrim (substr ($ exponent , 1 ), '0 ' ) ?: '0 ' ;
514+ $ exponent = filter_var ($ exponent , FILTER_VALIDATE_INT );
515+ if ($ exponent !== false ) {
516+ $ exponent = -$ exponent ;
517+ }
518+ } else {
519+ $ exponent = ltrim ($ exponent , '+0 ' ) ?: '0 ' ;
520+ $ exponent = filter_var ($ exponent , FILTER_VALIDATE_INT );
521+ }
522+ } else {
523+ $ exponent = 0 ;
524+ }
525+
526+ if ($ exponent === false || $ exponent === PHP_INT_MIN || $ exponent === PHP_INT_MAX ) {
509527 throw new NumberFormatException ('Exponent too large. ' );
510528 }
511529
You can’t perform that action at this time.
0 commit comments