File tree Expand file tree Collapse file tree 2 files changed +17
-8
lines changed
Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -107,7 +107,12 @@ func (n *BigDecimal) Quotient(other *BigDecimal) *BigDecimal {
107107}
108108
109109func (n * BigDecimal ) Remainder (other * BigDecimal ) * BigDecimal {
110- panic ("not implemented" )
110+ quotient := new (big.Float ).Quo (n .val , other .val )
111+ intQuotient , _ := quotient .Int (nil )
112+ intQuotientFloat := new (big.Float ).SetInt (intQuotient )
113+ product := new (big.Float ).Mul (intQuotientFloat , other .val )
114+ remainder := new (big.Float ).Sub (n .val , product )
115+ return & BigDecimal {val : remainder }
111116}
112117
113118func (n * BigDecimal ) Cmp (other * BigDecimal ) int {
Original file line number Diff line number Diff line change @@ -427,16 +427,20 @@ func (o ratioOps) Quotient(x, y any) any {
427427 return AsRatio (x ).Quotient (AsRatio (y ))
428428}
429429func (o ratioOps ) Remainder (x , y any ) any {
430- xRat := AsRatio (x )
431- yRat := AsRatio (y )
430+ xRat := AsRatio (x ). val
431+ yRat := AsRatio (y ). val
432432
433- q := new (big.Int )
434- q .Mul (xRat .val .Num (), yRat .val .Denom ())
433+ // BigInteger q = rx.numerator.multiply(ry.denominator).divide(
434+ // rx.denominator.multiply(ry.numerator));
435+ // Number ret = Numbers.minus(x, Numbers.multiply(q, y));
436+ // return ret
435437
436- qd := new (big.Int )
437- qd .Mul (xRat .val .Denom (), yRat .val .Num ())
438+ // result should be a BigInt
439+ qn := new (big.Int ).Mul (xRat .Num (), yRat .Denom ())
440+ qd := new (big.Int ).Mul (xRat .Denom (), yRat .Num ())
441+ rem := new (big.Int )
442+ q , rem := qn .QuoRem (qn , qd , rem )
438443
439- q .Div (q , qd )
440444 return Sub (x , Multiply (q , y ))
441445}
442446func (o ratioOps ) LT (x , y any ) bool {
You can’t perform that action at this time.
0 commit comments