Skip to content

Commit 0eef2ea

Browse files
committed
Add missing BigDecimal constant definitions.
1 parent 0299e6a commit 0eef2ea

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Bug fixes:
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).
77
* Fixed `BigDecimal#inspect` output for non-finite values (e.g, NaN or -Infinity) (#1683).
8+
* Added missing `BigDecimal` constant definitions (#1684).
89
* Implemented `rb_eval_string_protect`.
910
* Fixed `rb_get_kwargs` to correctly handle optional and rest arguments.
1011

lib/truffle/bigdecimal.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2015, 2017 Oracle and/or its affiliates. All rights reserved. This
1+
# Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved. This
22
# code is released under a tri EPL/GPL/LGPL license. You can use it,
33
# redistribute it and/or modify it under the terms of the:
44
#
@@ -11,7 +11,11 @@
1111
class BigDecimal < Numeric
1212
include Comparable
1313

14-
BASE = 10_000
14+
VERSION = '1.4.1'
15+
16+
BASE = 1_000_000_000
17+
INFINITY = Float::INFINITY
18+
NAN = Float::NAN
1519

1620
SIGN_NEGATIVE_INFINITE = -3
1721
SIGN_NEGATIVE_FINITE = -2
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
require_relative '../../spec_helper'
2+
require 'bigdecimal'
3+
4+
describe "BigDecimal constants" do
5+
ruby_version_is "2.5" do
6+
it "defines a VERSION value" do
7+
BigDecimal.const_defined?(:VERSION).should be_true
8+
end
9+
end
10+
11+
it "has a BASE value" do
12+
platform_is wordsize: 64 do
13+
BigDecimal::BASE.should == 1000000000
14+
end
15+
16+
platform_is wordsize: 32 do
17+
BigDecimal::BASE.should == 10000
18+
end
19+
end
20+
21+
it "has a NaN value" do
22+
BigDecimal::NAN.nan?.should be_true
23+
end
24+
25+
it "has an INFINITY value" do
26+
BigDecimal::INFINITY.infinite?.should == 1
27+
end
28+
29+
describe "exception-related constants" do
30+
[
31+
[:EXCEPTION_ALL, 0xff],
32+
[:EXCEPTION_INFINITY, 0x01],
33+
[:EXCEPTION_NaN, 0x02],
34+
[:EXCEPTION_UNDERFLOW, 0x04],
35+
[:EXCEPTION_OVERFLOW, 0x01],
36+
[:EXCEPTION_ZERODIVIDE, 0x10]
37+
].each do |const, value|
38+
it "has a #{const} value" do
39+
BigDecimal.const_get(const).should == value
40+
end
41+
end
42+
end
43+
44+
describe "rounding-related constants" do
45+
[
46+
[:ROUND_MODE, 0x100],
47+
[:ROUND_UP, 1],
48+
[:ROUND_DOWN, 2],
49+
[:ROUND_HALF_UP, 3],
50+
[:ROUND_HALF_DOWN, 4],
51+
[:ROUND_CEILING, 5],
52+
[:ROUND_FLOOR, 6],
53+
[:ROUND_HALF_EVEN, 7]
54+
].each do |const, value|
55+
it "has a #{const} value" do
56+
BigDecimal.const_get(const).should == value
57+
end
58+
end
59+
end
60+
61+
describe "sign-related constants" do
62+
[
63+
[:SIGN_NaN, 0],
64+
[:SIGN_POSITIVE_ZERO, 1],
65+
[:SIGN_NEGATIVE_ZERO, -1],
66+
[:SIGN_POSITIVE_FINITE, 2],
67+
[:SIGN_NEGATIVE_FINITE, -2],
68+
[:SIGN_POSITIVE_INFINITE, 3],
69+
[:SIGN_NEGATIVE_INFINITE, -3]
70+
].each do |const, value|
71+
it "has a #{const} value" do
72+
BigDecimal.const_get(const).should == value
73+
end
74+
end
75+
end
76+
end

0 commit comments

Comments
 (0)