Skip to content

Commit fa02252

Browse files
authored
Remove DECDIG=uint16_t branch. BigDecimal already requires uint64_t from v3.1.0 (#497)
1 parent af72ebd commit fa02252

File tree

8 files changed

+24
-98
lines changed

8 files changed

+24
-98
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
host:
2222
needs: ruby-versions
23-
name: ${{ matrix.os }} ${{ matrix.ruby }} decdig-${{ matrix.decdig_bits }}bit
23+
name: ${{ matrix.os }} ${{ matrix.ruby }}
2424
runs-on: ${{ matrix.os }}
2525
strategy:
2626
fail-fast: false
@@ -31,19 +31,14 @@ jobs:
3131
- macos-14
3232
- windows-latest
3333
ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
34-
decdig_bits: [32]
3534
include:
36-
- { os: ubuntu-latest, ruby: "3.4", decdig_bits: 16 }
3735
- { os: windows-latest , ruby: mingw }
3836
- { os: windows-latest , ruby: mswin }
3937
exclude:
40-
- { os: macos-latest , ruby: "2.5" }
41-
- { os: macos-14 , ruby: "2.5" }
4238
- { os: windows-latest , ruby: debug }
4339
- { os: windows-latest , ruby: truffleruby }
4440
- { os: windows-latest , ruby: truffleruby-head }
4541
env:
46-
BIGDECIMAL_USE_DECDIG_UINT16_T: ${{ matrix.decdig_bits == 16 }}
4742
BIGDECIMAL_USE_VP_TEST_METHODS: true
4843
BUNDLE_WITHOUT: sig
4944

ext/bigdecimal/bigdecimal.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,14 @@
2929
#endif
3030

3131
#include "bits.h"
32+
#include "ntt.h"
3233
#include "div.h"
3334
#include "static_assert.h"
3435

3536
#define BIGDECIMAL_VERSION "4.0.1"
3637

37-
#if SIZEOF_DECDIG == 4
38-
#define USE_NTT_MULTIPLICATION 1
39-
#include "ntt.h"
4038
#define NTT_MULTIPLICATION_THRESHOLD 100
4139
#define NEWTON_RAPHSON_DIVISION_THRESHOLD 200
42-
#endif
43-
4440
#define SIGNED_VALUE_MAX INTPTR_MAX
4541
#define SIGNED_VALUE_MIN INTPTR_MIN
4642
#define MUL_OVERFLOW_SIGNED_VALUE_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, SIGNED_VALUE_MIN, SIGNED_VALUE_MAX)
@@ -3279,7 +3275,6 @@ BigDecimal_vpmult(VALUE self, VALUE v) {
32793275
return c.bigdecimal;
32803276
}
32813277

3282-
#if SIZEOF_DECDIG == 4
32833278
VALUE
32843279
BigDecimal_nttmult(VALUE self, VALUE v) {
32853280
BDVALUE a,b,c;
@@ -3295,7 +3290,6 @@ BigDecimal_nttmult(VALUE self, VALUE v) {
32953290
RB_GC_GUARD(b.bigdecimal);
32963291
return c.bigdecimal;
32973292
}
3298-
#endif
32993293

33003294
#endif /* BIGDECIMAL_USE_VP_TEST_METHODS */
33013295

@@ -3670,9 +3664,7 @@ Init_bigdecimal(void)
36703664
rb_define_method(rb_cBigDecimal, "vpdivd_newton", BigDecimal_vpdivd_newton, 2);
36713665
rb_define_method(rb_cBigDecimal, "newton_raphson_inverse", BigDecimal_newton_raphson_inverse, 1);
36723666
rb_define_method(rb_cBigDecimal, "vpmult", BigDecimal_vpmult, 1);
3673-
#ifdef USE_NTT_MULTIPLICATION
36743667
rb_define_method(rb_cBigDecimal, "nttmult", BigDecimal_nttmult, 1);
3675-
#endif
36763668
#endif /* BIGDECIMAL_USE_VP_TEST_METHODS */
36773669

36783670
#define ROUNDING_MODE(i, name, value) \
@@ -4956,13 +4948,11 @@ VpMult(Real *c, Real *a, Real *b)
49564948
VpSetSign(c, VpGetSign(a) * VpGetSign(b)); /* set sign */
49574949
if (!AddExponent(c, b->exponent)) return 0;
49584950

4959-
#ifdef USE_NTT_MULTIPLICATION
49604951
if (b->Prec >= NTT_MULTIPLICATION_THRESHOLD) {
49614952
ntt_multiply((uint32_t)a->Prec, (uint32_t)b->Prec, a->frac, b->frac, c->frac);
49624953
c->Prec = a->Prec + b->Prec;
49634954
goto Cleanup;
49644955
}
4965-
#endif
49664956

49674957
carry = 0;
49684958
nc = ind_c = MxIndAB;
@@ -5059,13 +5049,11 @@ VpDivd(Real *c, Real *r, Real *a, Real *b)
50595049

50605050
if (word_a > word_r || word_b + word_c - 2 >= word_r) goto space_error;
50615051

5062-
#ifdef USE_NTT_MULTIPLICATION
50635052
// Newton-Raphson division requires multiplication to be faster than O(n^2)
50645053
if (word_c >= NEWTON_RAPHSON_DIVISION_THRESHOLD && word_b >= NEWTON_RAPHSON_DIVISION_THRESHOLD) {
50655054
VpDivdNewton(c, r, a, b);
50665055
goto Exit;
50675056
}
5068-
#endif
50695057

50705058
for (i = 0; i < word_a; ++i) r->frac[i] = a->frac[i];
50715059
for (i = word_a; i < word_r; ++i) r->frac[i] = 0;

ext/bigdecimal/bigdecimal.h

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,15 @@
1717
# include <float.h>
1818
#endif
1919

20-
#if defined(HAVE_INT64_T) && !defined(BIGDECIMAL_USE_DECDIG_UINT16_T)
21-
# define DECDIG uint32_t
22-
# define DECDIG_DBL uint64_t
23-
# define DECDIG_DBL_SIGNED int64_t
24-
# define SIZEOF_DECDIG 4
25-
# define PRI_DECDIG_PREFIX ""
26-
# ifdef PRI_LL_PREFIX
27-
# define PRI_DECDIG_DBL_PREFIX PRI_LL_PREFIX
28-
# else
29-
# define PRI_DECDIG_DBL_PREFIX "l"
30-
# endif
20+
#define DECDIG uint32_t
21+
#define DECDIG_DBL uint64_t
22+
#define DECDIG_DBL_SIGNED int64_t
23+
#define SIZEOF_DECDIG 4
24+
#define PRI_DECDIG_PREFIX ""
25+
#ifdef PRI_LL_PREFIX
26+
# define PRI_DECDIG_DBL_PREFIX PRI_LL_PREFIX
3127
#else
32-
# define DECDIG uint16_t
33-
# define DECDIG_DBL uint32_t
34-
# define DECDIG_DBL_SIGNED int32_t
35-
# define SIZEOF_DECDIG 2
36-
# define PRI_DECDIG_PREFIX "h"
37-
# define PRI_DECDIG_DBL_PREFIX ""
28+
# define PRI_DECDIG_DBL_PREFIX "l"
3829
#endif
3930

4031
#define PRIdDECDIG PRI_DECDIG_PREFIX"d"
@@ -51,31 +42,15 @@
5142
#define PRIxDECDIG_DBL PRI_DECDIG_DBL_PREFIX"x"
5243
#define PRIXDECDIG_DBL PRI_DECDIG_DBL_PREFIX"X"
5344

54-
#if SIZEOF_DECDIG == 4
55-
# define BIGDECIMAL_BASE ((DECDIG)1000000000U)
56-
# define BIGDECIMAL_COMPONENT_FIGURES 9
45+
#define BIGDECIMAL_BASE ((DECDIG)1000000000U)
46+
#define BIGDECIMAL_COMPONENT_FIGURES 9
5747
/*
5848
* The number of components required for a 64-bit integer.
5949
*
6050
* INT64_MAX: 9_223372036_854775807
6151
* UINT64_MAX: 18_446744073_709551615
6252
*/
63-
# define BIGDECIMAL_INT64_MAX_LENGTH 3
64-
65-
#elif SIZEOF_DECDIG == 2
66-
# define BIGDECIMAL_BASE ((DECDIG)10000U)
67-
# define BIGDECIMAL_COMPONENT_FIGURES 4
68-
/*
69-
* The number of components required for a 64-bit integer.
70-
*
71-
* INT64_MAX: 922_3372_0368_5477_5807
72-
* UINT64_MAX: 1844_6744_0737_0955_1615
73-
*/
74-
# define BIGDECIMAL_INT64_MAX_LENGTH 5
75-
76-
#else
77-
# error Unknown size of DECDIG
78-
#endif
53+
#define BIGDECIMAL_INT64_MAX_LENGTH 3
7954

8055
#define BIGDECIMAL_DOUBLE_FIGURES (1+DBL_DIG)
8156

ext/bigdecimal/extconf.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def have_builtin_func(name, check_expr, opt = "", &b)
5252
bigdecimal_rb = "$(srcdir)/../../lib/bigdecimal.rb"
5353
end
5454

55-
$defs.push '-DBIGDECIMAL_USE_DECDIG_UINT16_T' if ENV['BIGDECIMAL_USE_DECDIG_UINT16_T'] == 'true'
5655
$defs.push '-DBIGDECIMAL_USE_VP_TEST_METHODS' if ENV['BIGDECIMAL_USE_VP_TEST_METHODS'] == 'true'
5756

5857
create_makefile('bigdecimal') {|mf|

test/bigdecimal/helper.rb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@
55

66
module TestBigDecimalBase
77
BASE = BigDecimal::BASE
8-
case BASE
9-
when 1000000000
10-
SIZEOF_DECDIG = RbConfig::SIZEOF["int32_t"]
11-
BASE_FIG = 9
12-
when 10000
13-
SIZEOF_DECDIG = RbConfig::SIZEOF["int16_t"]
14-
BASE_FIG = 4
15-
end
8+
BASE_FIG = 9
169

1710
def setup
1811
@mode = BigDecimal.mode(BigDecimal::EXCEPTION_ALL)

test/bigdecimal/test_bigdecimal.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,8 @@ def test_BigDecimal_bug7522
108108
def test_BigDecimal_issue_192
109109
# https://github.com/ruby/bigdecimal/issues/192
110110
# https://github.com/rails/rails/pull/42125
111-
if BASE_FIG == 9
112-
int = 1_000_000_000_12345_0000
113-
big = BigDecimal("0.100000000012345e19")
114-
else # BASE_FIG == 4
115-
int = 1_0000_12_00
116-
big = BigDecimal("0.1000012e9")
117-
end
111+
int = 1_000_000_000_12345_0000
112+
big = BigDecimal("0.100000000012345e19")
118113
assert_equal(BigDecimal(int), big, "[ruby/bigdecimal#192]")
119114
end
120115

test/bigdecimal/test_bigdecimal_util.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,8 @@ def test_Float_to_d_bug13331
6565
def test_Float_to_d_issue_192
6666
# https://github.com/ruby/bigdecimal/issues/192
6767
# https://github.com/rails/rails/pull/42125
68-
if BASE_FIG == 9
69-
flo = 1_000_000_000.12345
70-
big = BigDecimal("0.100000000012345e10")
71-
else # BASE_FIG == 4
72-
flo = 1_0000.12
73-
big = BigDecimal("0.1000012e5")
74-
end
68+
flo = 1_000_000_000.12345
69+
big = BigDecimal("0.100000000012345e10")
7570
assert_equal(flo.to_d, big, "[ruby/bigdecimal#192]")
7671
end
7772

test/bigdecimal/test_vp_operation.rb

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ def setup
1313
end
1414
end
1515

16-
def ntt_mult_available?
17-
BASE_FIG == 9
18-
end
19-
2016
def test_vpmult
2117
assert_equal(BigDecimal('121932631112635269'), BigDecimal('123456789').vpmult(BigDecimal('987654321')))
2218
assert_equal(BigDecimal('12193263.1112635269'), BigDecimal('123.456789').vpmult(BigDecimal('98765.4321')))
@@ -26,7 +22,6 @@ def test_vpmult
2622
end
2723

2824
def test_nttmult
29-
omit 'NTT multiplication is only available for 32-bit DECDIG' unless ntt_mult_available?
3025
[*1..32].repeated_permutation(2) do |a, b|
3126
x = BigDecimal(10 ** (BASE_FIG * a) / 7)
3227
y = BigDecimal(10 ** (BASE_FIG * b) / 13)
@@ -68,10 +63,8 @@ def test_not_affected_by_limit
6863
BigDecimal.limit 3
6964
assert_equal(xy, x.vpmult(y))
7065
assert_equal(3, BigDecimal.limit)
71-
if ntt_mult_available?
72-
assert_equal(xy, x.nttmult(y))
73-
assert_equal(3, BigDecimal.limit)
74-
end
66+
assert_equal(xy, x.nttmult(y))
67+
assert_equal(3, BigDecimal.limit)
7568

7669
prec = (z.exponent - 1) / BASE_FIG - (y.exponent - 1) / BASE_FIG + 1
7770
assert_equal([x, mod], z.vpdivd(y, prec))
@@ -176,16 +169,9 @@ def test_vpdivd_large_prec_divisor
176169
end
177170

178171
def test_vpdivd_intermediate_zero
179-
if BASE_FIG == 9
180-
x = BigDecimal('123456789.246913578000000000123456789')
181-
y = BigDecimal('123456789')
182-
assert_vpdivd_equal([BigDecimal('1.000000002000000000000000001'), BigDecimal(0)], [x, y, 4])
183-
assert_vpdivd_equal([BigDecimal('1.000000000049999999'), BigDecimal('1e-18')], [BigDecimal("2.000000000099999999"), 2, 3])
184-
else
185-
x = BigDecimal('1234.246800001234')
186-
y = BigDecimal('1234')
187-
assert_vpdivd_equal([BigDecimal('1.000200000001'), BigDecimal(0)], [x, y, 4])
188-
assert_vpdivd_equal([BigDecimal('1.00000499'), BigDecimal('1e-8')], [BigDecimal("2.00000999"), 2, 3])
189-
end
172+
x = BigDecimal('123456789.246913578000000000123456789')
173+
y = BigDecimal('123456789')
174+
assert_vpdivd_equal([BigDecimal('1.000000002000000000000000001'), BigDecimal(0)], [x, y, 4])
175+
assert_vpdivd_equal([BigDecimal('1.000000000049999999'), BigDecimal('1e-18')], [BigDecimal("2.000000000099999999"), 2, 3])
190176
end
191177
end

0 commit comments

Comments
 (0)