Skip to content

Commit 0299e6a

Browse files
committed
[GR-15780] Fix BigDecimal#inspect to properly case non-finite values.
PullRequest: truffleruby/836
2 parents 93a4054 + 1adec69 commit 0299e6a

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
@@ -4,6 +4,7 @@ Bug fixes:
44

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

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)