Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit 908ad9a

Browse files
author
Andreu Correa Casablanca
committed
Simplified code to make it more understandable
1 parent 4b93585 commit 908ad9a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/Decimal.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
class Decimal
1818
{
1919
const CLASSIC_DECIMAL_NUMBER_REGEXP = '/^([+\-]?)0*(([1-9][0-9]*|[0-9])(\.[0-9]+)?)$/';
20-
const EXP_NOTATION_NUMBER_REGEXP = '/([+\-]?)0*([0-9](\.[0-9]+)?)[eE]([+\-]?)(\d+)/';
21-
const EXP_NUM_GROUPS_NUMBER_REGEXP = "/^ (?P<int> \d*) (?: \. (?P<dec> \d+) ) E (?P<sign>[\+\-]) (?P<exp>\d+) $/x";
20+
const EXP_NOTATION_NUMBER_REGEXP = '/^ (?P<sign> [+\-]?) 0*(?P<mantissa> [0-9](?P<decimals> \.[0-9]+)?) [eE] (?P<expSign> [+\-]?)(?P<exp> \d+)$/x';
21+
const EXP_NUM_GROUPS_NUMBER_REGEXP = '/^ (?P<int> \d*) (?: \. (?P<dec> \d+) ) E (?P<sign>[\+\-]) (?P<exp>\d+) $/x';
2222

2323
/**
2424
* Internal numeric value
@@ -135,11 +135,11 @@ public static function fromString(string $strValue, int $scale = null, bool $rem
135135
} elseif (\preg_match(self::EXP_NOTATION_NUMBER_REGEXP, $strValue, $captures) === 1) {
136136
list($min_scale, $value) = self::fromExpNotationString(
137137
$scale,
138-
$captures[1],
139-
$captures[2],
140-
$captures[3],
141-
$captures[4],
142-
(int)$captures[5]
138+
$captures['sign'],
139+
$captures['mantissa'],
140+
\strlen($captures['mantissa']) - 1,
141+
$captures['expSign'],
142+
(int)$captures['exp']
143143
);
144144
} else {
145145
throw new NaNInputError('strValue must be a number');
@@ -1092,12 +1092,12 @@ private static function fromExpNotationString(
10921092
int $scale = null,
10931093
string $sign,
10941094
string $mantissa,
1095-
string $mantissaDecimals,
1095+
int $nDecimals,
10961096
string $expSign,
10971097
int $expVal
10981098
): array
10991099
{
1100-
$mantissaScale = \max(\strlen($mantissaDecimals) - 1, 0);
1100+
$mantissaScale = \max($nDecimals, 0);
11011101

11021102
if (self::normalizeSign($expSign) === '') {
11031103
$minScale = \max($mantissaScale - $expVal, 0);

0 commit comments

Comments
 (0)