Skip to content


[Truffle] Fixed Findbugs failure related to comparing two floating po…
Browse files Browse the repository at this point in the history
…int values.
  • Loading branch information
nirvdrum committed Mar 9, 2015
1 parent 21781d0 commit 1db3a92
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public static void format(RubyContext context, PrintStream stream, String format
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) {
if ((value - Math.rint(value)) == 0) {

This comment has been minimized.

Copy link

eregon Mar 12, 2015


I didn't about Math.rint, nice!
But what if a double can represent perfectly the integral value? For 2^54-1 for instance.
I guess it does not matter too much, since anyway such big values are printed in scientific form with %g.

This comment has been minimized.

Copy link

nirvdrum Mar 12, 2015

Author Contributor

If you have better ideas on how to fix it, please let me know. I was doing the equality check against a casted value to see if it would perfectly fit (within a reasonable amount of precision), but that caused a FindBugs warning so I changed to this.

If it helps any, MRI doesn't track arbitrary precision for this formatter.

stream.print(String.valueOf((long) value));
} else {
Expand Down

0 comments on commit 1db3a92

Please sign in to comment.