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: 6a73ac8e1059
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a490ad17208e
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Mar 9, 2015

  1. Copy the full SHA
    5fb8b65 View commit details
  2. Copy the full SHA
    a490ad1 View commit details
Showing with 22 additions and 1 deletion.
  1. +22 −1 truffle/src/main/java/org/jruby/truffle/runtime/core/StringFormatter.java
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ public static void format(RubyContext context, PrintStream stream, String format

precision = Integer.parseInt(format.substring(precisionStart, n));
} else {
precision = 5;
precision = 6;
}

if (format.charAt(n) == ' ') {
@@ -182,6 +182,27 @@ public static void format(RubyContext context, PrintStream stream, String format
break;
}

case 'g': {
/**
* General approach taken from StackOverflow: http://stackoverflow.com/questions/703396/how-to-nicely-format-floating-numbers-to-string-without-unnecessary-decimal-0
* Answers provided by JasonD (http://stackoverflow.com/users/1288598/jasond) and Darthenius (http://stackoverflow.com/users/974531/darthenius)
* Licensed by cc-wiki license: http://creativecommons.org/licenses/by-sa/3.0/
*/

// TODO (nirvdrum 09-Mar-15) Make this adhere to the MRI invariant: "single-precision, network (big-endian) byte order"

final double value = CoreLibrary.toDouble(values.get(v));

// If the value is a long value stuffed in a double, cast it so we don't print a trailing ".0".
if (value == (long) value) {
stream.print(String.valueOf((long) value));
} else {
stream.print(String.valueOf(value));
}

break;
}

default:
throw new RuntimeException("Kernel#sprintf error -- unknown format: " + type);
}