Version 4.6.0

This commit is contained in:
Neo committed 2025-12-19 05:55:31 -08:00
1 parent f79dcf067a
commit 517a5e1f70
2036 files changed
+110041 -26162

No files matched your search

+15 -14
View File
@@ -294,9 +294,17 @@ class _Number implements \JsonSerializable
$precision++;
}
/* Work out the remainder from ( $x * ( 10 ^ $precision ) / $number ) */
$result = 0;
$this->multiply( new Number( (string) pow( 10, $precision ) ) )->modulus( $number, $result );
/* If the bcmath extension is available, we can use bcdiv to do this effectively */
if ( \extension_loaded('bcmath') )
{
$result = str_replace( '.', '', bcdiv( (string) $this->absolute(), (string) $number->absolute(), $precision ) ); // It will automatically return with correct $precision - e.g. "1.000" rather than "1", so we can just strip the decimal to get the absolute value we need
}
/* Otherwise we have to work out the remainder from ( $x * ( 10 ^ $precision ) / $number ) */
else
{
$result = 0;
$this->absolute()->multiply( new Number( (string) pow( 10, $precision ) ) )->modulus( $number->absolute(), $result );
}
/* Round it */
if ( $round !== static::ROUND_TRUNCATE )
@@ -459,29 +467,22 @@ class _Number implements \JsonSerializable
}
/* Start with a number without the decimal point, truncated where we need it */
$abs = ( $this->positive === FALSE ? "-" : '' ) . "{$this->beforeDecimalPoint}" . str_pad( \substr( str_pad( $this->afterDecimalPoint, $this->numberOfDecimalPlaces, '0', STR_PAD_LEFT ), 0, $decimalPlaces ), $decimalPlaces, '0', STR_PAD_LEFT );
$abs = "{$this->beforeDecimalPoint}" . str_pad( \substr( str_pad( $this->afterDecimalPoint, $this->numberOfDecimalPlaces, '0', STR_PAD_LEFT ), 0, $decimalPlaces ), $decimalPlaces, '0', STR_PAD_LEFT );
/* If we're going up, add one on */
if ( $round === static::ROUND_UP )
{
if ( $this->positive )
{
$abs = \intval( $abs ) + 1;
}
else
{
$abs = \intval( $abs ) - 1;
}
$abs = \intval( $abs ) + 1;
}
/* Put the decimal back */
if ( $decimalPlaces )
{
return new static( \substr( $abs, 0, -$decimalPlaces ) . '.' . str_pad( \substr( $abs, -$decimalPlaces ), $decimalPlaces, '0', STR_PAD_LEFT ) );
return new static( ( $this->positive === FALSE ? "-" : '' ) . \substr( $abs, 0, -$decimalPlaces ) . '.' . str_pad( \substr( $abs, -$decimalPlaces ), $decimalPlaces, '0', STR_PAD_LEFT ) );
}
else
{
return new static( "{$abs}" );
return new static( ( $this->positive === FALSE ? "-" : '' ) . "{$abs}" );
}
}