adjustLastDigit modifies d = x-currentDiff*ε, to get closest to d = x-targetDiff*ε, without becoming smaller than x-maxDiff*ε. It assumes that a decimal digit is worth ulpDecimal*ε, and that all data is known with a error estimate of ulpBinary*ε.
(d *decimalSlice, currentDiff, targetDiff, maxDiff, ulpDecimal, ulpBinary uint64)
| 643 | // It assumes that a decimal digit is worth ulpDecimal*ε, and that |
| 644 | // all data is known with a error estimate of ulpBinary*ε. |
| 645 | func adjustLastDigit(d *decimalSlice, currentDiff, targetDiff, maxDiff, ulpDecimal, ulpBinary uint64) bool { |
| 646 | if ulpDecimal < 2*ulpBinary { |
| 647 | // Approximation is too wide. |
| 648 | return false |
| 649 | } |
| 650 | for currentDiff+ulpDecimal/2+ulpBinary < targetDiff { |
| 651 | d.d[d.nd-1]-- |
| 652 | currentDiff += ulpDecimal |
| 653 | } |
| 654 | if currentDiff+ulpDecimal <= targetDiff+ulpDecimal/2+ulpBinary { |
| 655 | // we have two choices, and don't know what to do. |
| 656 | return false |
| 657 | } |
| 658 | if currentDiff < ulpBinary || currentDiff > maxDiff-ulpBinary { |
| 659 | // we went too far |
| 660 | return false |
| 661 | } |
| 662 | if d.nd == 1 && d.d[0] == '0' { |
| 663 | // the number has actually reached zero. |
| 664 | d.nd = 0 |
| 665 | d.dp = 0 |
| 666 | } |
| 667 | return true |
| 668 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…