Commit graph

151 commits

Author SHA1 Message Date
Maciej Rzasa
36e3d46d35 [ruby/bigdecimal] Handle correctly #remainder with infinity. Fixes
https://github.com/ruby/bigdecimal/pull/187

4b8572d452
2023-02-17 17:46:27 +00:00
Benoit Daloze
47b66a5acd [ruby/bigdecimal] Add truffleruby in CI
5a25e26e08
2023-01-27 11:07:06 +00:00
Kenta Murata
ef1c6109b1 [ruby/bigdecimal] Tweak check_rounding_mode_option
e1c6c9be25
2022-11-13 02:02:02 +00:00
Kenta Murata
7db195d521
[ruby/bigdecimal] Fix the maximum precision of the quotient
Fixes https://github.com/ruby/bigdecimal/pull/220

127a1b5a31
2022-01-24 10:56:30 +09:00
Kenta Murata
506728d0b8
[ruby/bigdecimal] Fix typo
79c09b4dac
2022-01-24 10:56:25 +09:00
Kenta Murata
a1d9fbef05
[ruby/bigdecimal] Fix the result precision of BigDecimal#divmod
a32f6cb9e2
2021-12-24 02:29:01 +09:00
Kenta Murata
79712fc083
[ruby/bigdecimal] Let BigDecimal#quo accept precision
Fix GH-214.

13e0e93f37
2021-12-24 02:29:00 +09:00
Kenta Murata
98918209b7
[ruby/bigdecimal] Allow passing both float and precision in BigDecimal#div
Fix GH-212.

900bb7fcf5
2021-12-24 02:29:00 +09:00
Kenta Murata
84ae7a5df9
[ruby/bigdecimal] Add BigDecimal#precision_scale
c019caeaba
2021-12-24 02:28:59 +09:00
Kenta Murata
aca96f7ec7
[ruby/bigdecimal] Add BigDecimal#scale
Fixes GH-198.

4fbec55680
2021-12-24 02:28:58 +09:00
Kenta Murata
d905abb457
[ruby/bigdecimal] Fix BigDecimal#precision for single DECDIG case
Fix GH-205

7d198394a2
2021-12-24 02:28:56 +09:00
Kenta Murata
75f552e973
[ruby/bigdecimal] Fix the precision of the adjusted quotient
8dc8cd339d
2021-12-24 02:28:56 +09:00
Kenta Murata
7b2cfce543
[ruby/bigdecimal] Let BigDecimal_DoDivmod use the same precision calculation as BigDecimal_divide
11cb2c8840
2021-12-24 02:28:55 +09:00
Kenta Murata
e1265c8198
[ruby/bigdecimal] Use larger precision in divide for irrational or recurring results
Just in case for irrational or recurring results, the precision of the
quotient is set to at least more than 2*Float::DIG plus alpha.

[Bug #13754] [Fix GH-94]

99442c75d3
2021-12-24 02:28:55 +09:00
Kenta Murata
b2a74948b6
[ruby/bigdecimal] Add tests for the issue GH-192
e864828b47
2021-12-24 02:28:54 +09:00
Kenta Murata
70f2b62dfe
[ruby/bigdecimal] Use values in RbConfig::LIMITS in test
14e35f5a70
2021-12-24 02:28:52 +09:00
Kenta Murata
247d8d2815
[ruby/bigdecimal] Fix the style in test/bigdecimal/test_bigdecimal.rb
aa31ef2f33
2021-12-24 02:28:51 +09:00
Jean Boussier
ec478d947f
[ruby/bigdecimal] Fix negative Bignum conversion
Introduced in 4792a917d8

`rb_absint_size` return the number of bytes needed to fit
the absolute integer, but negative integers need the sign, so one more
bit, and potentially one more byte.

0f3d5d0eb7
2021-12-24 02:28:51 +09:00
Kenta Murata
c539cfd235
[ruby/bigdecimal] Fix test against #196
a834eb92a2
2021-12-24 02:28:51 +09:00
Hiroshi SHIBATA
93691d0752
Import bigdecimal-3.1.0.dev 2021-10-22 15:53:49 +09:00
Kenta Murata
b130644584 [ruby/bigdecimal] Fix for the coerce cases in divide and DoDivmod
1cb92487f7
2021-01-16 00:09:26 +09:00
Kenta Murata
a5b4b806de
[ruby/bigdecimal] Allow digits=0 in BigDecimal(flt) and Float#to_d
Using dtoa of mode=0, we can determine the number of digits in decimal that is
necessary to represent the given Float number without errors.

This change permits digits=0 in BigDecimal(flt) and Float#to_d, and these
methods use dtoa of mode=0 when the given digits is 0.

Internal implicit conversion from Float also uses digits=0.

[Fix GH-70]

2dbe170e35
2021-01-13 11:49:18 +09:00
Kenta Murata
2175c2c957 [ruby/bigdecimal] Use pre-allocated objects for special values
95c201f2d3
2021-01-13 01:58:23 +09:00
Kenta Murata
6670de82c2
[ruby/bigdecimal] Fix exception message raised in Kernel.BigDecimal
d163f170a4
ff8eeeb064
2021-01-13 01:27:04 +09:00
Kenta Murata
89f3125207 [ruby/bigdecimal] Add test cases of conversion from Float
28d3836366
2021-01-09 20:35:08 +09:00
Kenta Murata
82f6085b3e [ruby/bigdecimal] Fix trailing zero handling in rb_uint64_convert_to_BigDecimal
2056604d56
2021-01-07 10:20:40 +09:00
Kenta Murata
698d7947c3 [ruby/bigdecimal] Include TestBigDecimalBase in TestBigDecimalUtil
f732201df1
2021-01-07 10:19:46 +09:00
Kenta Murata
c2c0147538
[ruby/bigdecimal] Fix test for Ruby 2.4
Ruby 2.4 does not have RbConfig::LIMITS.

c8087523b0
2021-01-02 00:54:09 +09:00
Kenta Murata
448a67cd81
[ruby/bigdecimal] Implement special conversions for 64-bit integers
This change improves the conversion speed from small integers.

```
Comparison:
                           big_n9
              master:   4003688.9 i/s
    bigdecimal 3.0.0:   1270551.0 i/s - 3.15x  slower

                          big_n19
              master:   5410096.4 i/s
    bigdecimal 3.0.0:   1000250.3 i/s - 5.41x  slower
```

3429bd7e6f
2021-01-02 00:54:09 +09:00
Kenta Murata
5ee6830abe [ruby/bigdecimal] Fix test_limit
Keep the default value of BigDecimal.limit by BigDecimal.save_limit
to avoid failures of the other test methods due to the unexpected limit.

bdc1cc6585
2021-01-02 00:30:57 +09:00
Kenta Murata
8355a3e17b
[bigdecimal] Fix deprecation warning test 2020-12-19 22:13:59 +09:00
Kenta Murata
df3deb3baa
[bigdecimal] Add BigDecimal#n_significant_digits
981dc48f95
9ecf880ec0
2020-12-19 22:13:59 +09:00
Kenta Murata
654f6fbf19
[bigdecimal] Make BigDecimal#precs deprecated
7e80e6e145
0ed7846e8c
2020-12-19 22:13:58 +09:00
Kenta Murata
ff9e40811c
[bigdecimal] Add BigDecimal#precision
458eb66c49
2020-12-19 22:13:58 +09:00
Kenta Murata
928a06723d
[bigdecimal] Make bigdecimal Ractor safe
93fc392640
a90d13c4d0
2020-12-19 22:13:57 +09:00
Kenta Murata
e1424c3501
[bigdecimal] Fix the default precision of Float#to_d
Fix https://github.com/ruby/bigdecimal/issues/70
[Bug #13331]

aa536cd4b5
2020-12-19 22:13:53 +09:00
Kenta Murata
7b06085c7b
[bigdecimal] Fix test for d5ab8e8562 2020-12-19 02:44:20 +09:00
Kenta Murata
a86c147579
Import bigdecimal 2.0.2 (#3905)
* remove duplicated include

* Make BigDecimal#round with argument < 1 return Integer

Fixes [Bug #12780]

* Use a higher default precision for BigDecimal#power and #**

When a fractional power is given, increase the precision if the
precision isn't specified via power's second argument:

Float: increase by 15 (rough number of decimal precision in float)
BigDecimal: increase by adding similar precision modifier as done to
            calculate the base precision.
Rational: double the precision, since a BigDecimal is created, but
          the created BigDecimal uses the same precision.

Increasing the precision for these power calculations has the obvious
tradeoff of making the calculations slower.

Fixes Ruby Bug #17264

* Use DBLE_FIG for a Float value

* Version 2.0.1

Co-authored-by: pavel <pavel.rosicky@easy.cz>
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
2020-12-15 15:17:15 +09:00
Kenta Murata
9b433d34da
bidecimal: improve tests' independence (#3297)
Tests depending on the rounding mode must specify the appropriate rounding
mode and restore to the original mode at the end.
2020-07-12 17:30:29 +09:00
Kenta Murata
6a826eb4b0
[ruby/bigdecimal] Return US-ASCII string from BigDecimal#to_s
Fixes #159

57ee92e700
2020-07-06 01:15:47 +09:00
Kenta Murata
03a33603c6
[ruby/bigdecimal] Add Complex#to_d
97e794ac97
2020-07-06 01:15:46 +09:00
Jeremy Evans
6607212224
[ruby/bigdecimal] Make tests pass on Ruby 2.4
9d19e842ee
2020-07-06 01:15:46 +09:00
Jeremy Evans
d36b197d7c
[ruby/bigdecimal] Remove definition of BigDecimal#initialize_copy
This leaves the default definition, which will raise FrozenError.

05e843d838
2020-07-06 01:15:46 +09:00
Kenta Murata
f00efef30a
[ruby/bigdecimal] Support a Complex in Kernel.BigDecimal()
00795cb01f
2020-07-06 01:15:46 +09:00
Jeremy Evans
ceb9d516c6
[ruby/bigdecimal] Undef BigDecimal#initialize_copy
Both BigDecimal#clone and BigDecimal#dup return self, there is no
reason to have initialize_copy exposed as a Ruby method.

The same is true for initialize_clone and initialize_dup.

aaf237fa9e
2020-07-06 01:15:45 +09:00
Nobuyoshi Nakada
6236bbf363
Removed duplicate test with test_BigDecimal_bug7522 2020-07-05 22:02:59 +09:00
Jeremy Evans
ab42e5a486 More fixes for $SAFE/taint post merging 2019-11-18 01:00:25 +02:00
Jeremy Evans
ffd0820ab3 Deprecate taint/trust and related methods, and make the methods no-ops
This removes the related tests, and puts the related specs behind
version guards.  This affects all code in lib, including some
libraries that may want to support older versions of Ruby.
2019-11-18 01:00:25 +02:00
Jeremy Evans
b38b26c62d
[ruby/bigdecimal] Remove taint checking
This removes the taint checking.  Taint support is deprecated in
Ruby 2.7 and has no effect.  I don't think removing the taint
checks in earlier ruby versions will cause any problems.

1918d466f3
2019-11-12 11:16:07 +09:00
Kenta Murata
dd0c75fdc2
Import changes from ruby/bigdecimal (#2531)
Sync to ruby/bigdecimal@92356ba71c
2019-10-08 09:06:28 +09:00