Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 256042b90d1f
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7f9866b41251
Choose a head ref
  • 2 commits
  • 1 file changed
  • 2 contributors

Commits on Sep 15, 2016

  1. Format initial string to specific precision, so rounding works.

    The logic in our double-based sprintf logic attempts to round
    values manually by inspecting a long-form version of the double.
    If we need to round, and the next digit is a five, it will round
    toward zero (truncate) iff that five is the last digit in the long
    unrounded string. This appears to have been an attempt to mimic
    C printf's behavior of rounding "true half" to even in the
    presence of inaccurately-represented IEEE754 decimals.
    
    This commit changes the pre-formatting to actually format with the
    specified precision, allowing NumberFormat's default HALF_EVEN
    logic to to the work for us.
    
    Fixes #4157.
    headius committed Sep 15, 2016
    Copy the full SHA
    6cef061 View commit details

Commits on Oct 12, 2016

  1. Merge pull request #4159 from headius/sprintf_rounding

    Format initial string to specific precision, so rounding works.
    enebo authored Oct 12, 2016
    Copy the full SHA
    7f9866b View commit details
Showing with 5 additions and 4 deletions.
  1. +5 −4 core/src/main/java/org/jruby/util/Sprintf.java
9 changes: 5 additions & 4 deletions core/src/main/java/org/jruby/util/Sprintf.java
Original file line number Diff line number Diff line change
@@ -864,8 +864,12 @@ else if ((flags & FLAG_MINUS) != 0) {
break;
}

if ((flags & FLAG_PRECISION) == 0) {
precision = 6;
}

NumberFormat nf = getNumberFormat(args.locale);
nf.setMaximumFractionDigits(Integer.MAX_VALUE);
nf.setMaximumFractionDigits(precision);
String str = nf.format(dval);

// grrr, arghh, want to subclass sun.misc.FloatingDecimal, but can't,
@@ -963,9 +967,6 @@ else if ((flags & FLAG_MINUS) != 0) {
} else {
signChar = 0;
}
if ((flags & FLAG_PRECISION) == 0) {
precision = 6;
}

switch(fchar) {
case 'E':