QuoInteger sets d to the integer part of the quotient x/y. If the result cannot fit in d.Precision digits, an error is returned.
(d, x, y *Decimal)
| 368 | // QuoInteger sets d to the integer part of the quotient x/y. If the result |
| 369 | // cannot fit in d.Precision digits, an error is returned. |
| 370 | func (c *Context) QuoInteger(d, x, y *Decimal) (Condition, error) { |
| 371 | if set, res, err := c.quoSpecials(d, x, y, false); set { |
| 372 | return res, err |
| 373 | } |
| 374 | |
| 375 | // The sign of the result is the exclusive or of the signs of the operands. |
| 376 | neg := x.Negative != y.Negative |
| 377 | var res Condition |
| 378 | |
| 379 | var tmp BigInt |
| 380 | a, b, _, err := upscale(x, y, &tmp) |
| 381 | if err != nil { |
| 382 | return 0, fmt.Errorf("QuoInteger: %w", err) |
| 383 | } |
| 384 | d.Coeff.Quo(a, b) |
| 385 | d.Form = Finite |
| 386 | if d.NumDigits() > int64(c.Precision) { |
| 387 | d.Set(decimalNaN) |
| 388 | res |= DivisionImpossible |
| 389 | } |
| 390 | d.Exponent = 0 |
| 391 | d.Negative = neg |
| 392 | return c.goError(res) |
| 393 | } |
| 394 | |
| 395 | // Rem sets d to the remainder part of the quotient x/y. If |
| 396 | // the integer part cannot fit in d.Precision digits, an error is returned. |