8
8
use Brick \Math \Exception \MathException ;
9
9
use Brick \Math \Exception \NegativeNumberException ;
10
10
use Brick \Math \Internal \Calculator ;
11
+ use Override ;
11
12
12
13
/**
13
14
* Immutable, arbitrary-precision signed decimal numbers.
@@ -47,6 +48,7 @@ protected function __construct(string $value, int $scale = 0)
47
48
/**
48
49
* @psalm-pure
49
50
*/
51
+ #[Override]
50
52
protected static function from (BigNumber $ number ): static
51
53
{
52
54
return $ number ->toBigDecimal ();
@@ -535,6 +537,7 @@ public function negated() : BigDecimal
535
537
return new BigDecimal (Calculator::get ()->neg ($ this ->value ), $ this ->scale );
536
538
}
537
539
540
+ #[Override]
538
541
public function compareTo (BigNumber |int |float |string $ that ) : int
539
542
{
540
543
$ that = BigNumber::of ($ that );
@@ -552,6 +555,7 @@ public function compareTo(BigNumber|int|float|string $that) : int
552
555
return - $ that ->compareTo ($ this );
553
556
}
554
557
558
+ #[Override]
555
559
public function getSign () : int
556
560
{
557
561
return ($ this ->value === '0 ' ) ? 0 : (($ this ->value [0 ] === '- ' ) ? -1 : 1 );
@@ -609,18 +613,21 @@ public function hasNonZeroFractionalPart() : bool
609
613
return $ this ->getFractionalPart () !== \str_repeat ('0 ' , $ this ->scale );
610
614
}
611
615
616
+ #[Override]
612
617
public function toBigInteger () : BigInteger
613
618
{
614
619
$ zeroScaleDecimal = $ this ->scale === 0 ? $ this : $ this ->dividedBy (1 , 0 );
615
620
616
621
return self ::newBigInteger ($ zeroScaleDecimal ->value );
617
622
}
618
623
624
+ #[Override]
619
625
public function toBigDecimal () : BigDecimal
620
626
{
621
627
return $ this ;
622
628
}
623
629
630
+ #[Override]
624
631
public function toBigRational () : BigRational
625
632
{
626
633
$ numerator = self ::newBigInteger ($ this ->value );
@@ -629,6 +636,7 @@ public function toBigRational() : BigRational
629
636
return self ::newBigRational ($ numerator , $ denominator , false );
630
637
}
631
638
639
+ #[Override]
632
640
public function toScale (int $ scale , RoundingMode $ roundingMode = RoundingMode::UNNECESSARY ) : BigDecimal
633
641
{
634
642
if ($ scale === $ this ->scale ) {
@@ -638,16 +646,19 @@ public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::U
638
646
return $ this ->dividedBy (BigDecimal::one (), $ scale , $ roundingMode );
639
647
}
640
648
649
+ #[Override]
641
650
public function toInt () : int
642
651
{
643
652
return $ this ->toBigInteger ()->toInt ();
644
653
}
645
654
655
+ #[Override]
646
656
public function toFloat () : float
647
657
{
648
658
return (float ) (string ) $ this ;
649
659
}
650
660
661
+ #[Override]
651
662
public function __toString () : string
652
663
{
653
664
if ($ this ->scale === 0 ) {
0 commit comments