Commit 13b78c2
fix: correct divRound rounding for negative operands (#320)
* fix: correct divRound rounding for negative operands
divRound computed the half-way threshold and the round-up direction
from the raw operands, which only works when both are positive. With a
negative dividend or divisor it compared a signed remainder against a
value derived from the signed divisor, rounded in the wrong direction,
and lost the sign when the truncated quotient was zero.
Compare the magnitude of the remainder against half of the absolute
divisor and step the quotient away from zero using the sign of the
result, so rounding matches the positive case for every sign.
* fix: normalize sign when imuln multiplies by zero (#321)
* fix: normalize sign when imuln multiplies by zero
Multiplying a negative number by the plain number 0 zeroed the words
but left the negative flag set, producing a negative zero. That value
reported isNeg() as true, was not eq() to zero, compared as less than
zero, and printed as -0. Clear the sign along with the length when the
factor is zero so the result is a plain zero.
* use _normSign()
---------
Co-authored-by: Kirill Fomichev <fanatid@ya.ru>
* add more tests
---------
Co-authored-by: Kirill Fomichev <fanatid@ya.ru>
(cherry picked from commit 73fb9a4)1 parent 9c6ef2f commit 13b78c2
2 files changed
Lines changed: 69 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2469 | 2469 | | |
2470 | 2470 | | |
2471 | 2471 | | |
2472 | | - | |
| 2472 | + | |
2473 | 2473 | | |
2474 | | - | |
2475 | | - | |
| 2474 | + | |
| 2475 | + | |
2476 | 2476 | | |
2477 | 2477 | | |
2478 | 2478 | | |
2479 | 2479 | | |
2480 | 2480 | | |
2481 | | - | |
2482 | | - | |
| 2481 | + | |
| 2482 | + | |
| 2483 | + | |
| 2484 | + | |
2483 | 2485 | | |
2484 | 2486 | | |
2485 | 2487 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
443 | 443 | | |
444 | 444 | | |
445 | 445 | | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
446 | 505 | | |
447 | 506 | | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
448 | 510 | | |
449 | 511 | | |
450 | 512 | | |
| |||
0 commit comments