Skip to content

Commit 4379ac7

Browse files
authored
#33 fix (#35)
1 parent 834c41e commit 4379ac7

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

src/BCMathExtended/BC.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,11 @@ protected static function checkIsFloat(string $number): bool
9393
protected static function powFractional(string $leftOperand, string $rightOperand, ?int $scale = null): string
9494
{
9595
// we need to increased scale to get correct results and avoid rounding error
96-
$increasedScale = $scale ?? self::getScale();
97-
$increasedScale *= 2;
98-
$decimals = explode('.', $rightOperand);
96+
$currentScale = $scale ?? self::getScale();
97+
$increasedScale = $currentScale * 2;
9998

100-
return self::checkNumber(
101-
self::mul(
102-
self::exp(
103-
self::mul(
104-
self::log($leftOperand),
105-
'0.' . $decimals[1],
106-
$increasedScale
107-
)
108-
),
109-
self::pow($leftOperand, $decimals[0], $increasedScale),
110-
$scale
111-
)
112-
);
99+
// add zero to trim scale
100+
return self::checkNumber(self::add(self::exp(self::mul($rightOperand, self::log($leftOperand), $increasedScale)), '0', $currentScale));
113101
}
114102

115103
public static function getScale(): int

tests/Unit/BCTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ public function powProvider(): array
710710
['1', '10', '0.0000001', 0],
711711
['1', '10', '0.0000001', 2],
712712
['36.029', '5.1', '2.2', 3],
713+
['0.5492944034820568190269179209773099881437', '1.005', '-120.12345678', 40]
713714
];
714715
}
715716

0 commit comments

Comments
 (0)