Skip to content

Commit 1adec69

Browse files
committed
Fix BigDecimal#inspect to properly case non-finite values.
1 parent 79898d8 commit 1adec69

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Bug fixes:
44

55
* Fixed `BigDecimal#dup` so it now just returns the receiver, per Ruby 2.5+ semantics (#1680).
6+
* Fixed `BigDecimal#inspect` output for non-finite values (e.g, NaN or -Infinity) (#1683).
67
* Implemented `rb_eval_string_protect`.
78
* Fixed `rb_get_kwargs` to correctly handle optional and rest arguments.
89

lib/truffle/bigdecimal.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def to_s(format = 'E')
245245
end
246246

247247
def inspect
248-
to_s.downcase
248+
finite? ? to_s.downcase : to_s
249249
end
250250

251251
def _dump(level=nil)

spec/ruby/library/bigdecimal/inspect_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@
1414
it "looks like this" do
1515
@bigdec.inspect.should == "0.12345678e4"
1616
end
17+
18+
it "properly cases non-finite values" do
19+
BigDecimal("NaN").inspect.should == "NaN"
20+
BigDecimal("Infinity").inspect.should == "Infinity"
21+
BigDecimal("+Infinity").inspect.should == "Infinity"
22+
BigDecimal("-Infinity").inspect.should == "-Infinity"
23+
end
1724
end

0 commit comments

Comments
 (0)