Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions php-toolkit/Common/RationalNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ public static function fromRational(Rational $rational): static
*/
public function round(int $precision = 0): static
{
$rollIn = pow(10, $precision + 1);
$rollIn = 10 ** ($precision + 1);
$roundInc = ($this->getWholePart() + $this->getNumerator() < 0) ? -5 : 5;
$integralPart = $this->getWholePart();
// this should in principle reduce the chance of overflow ...
$fractional = $this->sub($integralPart);
return new static($integralPart, intdiv($fractional->mul($rollIn)->whole + $roundInc, 10), $rollIn / 10);
return new static($integralPart, intdiv((int)($fractional->mul($rollIn)->whole + $roundInc), 10), (int)($rollIn / 10));
}

/**
Expand Down Expand Up @@ -189,8 +189,8 @@ public function toDecimal(int $scale = -1, int $precision = 0):string
$result .= '.' . $fractionalPart;
return $sign < 0 ? '-' . $result : $result;
}
$rollIn = pow(10, $scale + 1);
$fixedPoint = str_pad(intdiv($abs->mul($rollIn)->whole + 5, 10), $scale + 1, '0', STR_PAD_LEFT);
$rollIn = 10 ** ($scale + 1);
$fixedPoint = str_pad((string)intdiv((int)($abs->mul($rollIn)->whole + 5), 10), $scale + 1, '0', STR_PAD_LEFT);
$integralPart = substr($fixedPoint, 0, -$scale);
$fractionalPart = substr($fixedPoint, -$scale);
$result = $integralPart . '.' . $fractionalPart;
Expand Down Expand Up @@ -229,7 +229,7 @@ public static function fromDecimal(string|int $decimal): static
$sign = $matches[1][0] == '-' ? -1 : 1;
$integralPart = empty($matches[2]) ? 0 : (int)$matches[2][0];
$numerator = empty($matches[3]) ? 0 : (int)$matches[3][0];
$denominator = pow(10, strlen($matches[3][0] ?? ''));
$denominator = 10 ** strlen($matches[3][0] ?? '');
return new static($sign * $integralPart, $sign * $numerator, $denominator);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ private function stripCommonPrefix(string $entityName): string
if (str_starts_with($entityName, $this->commonPrefix)) {
return substr($entityName, strlen($this->commonPrefix));
}
return $this->commonPrefix;
}

/**
Expand Down