Giter VIP home page Giter VIP logo

bigdecimal's Issues

Win 10, Can't Update: MSYS2 Required

After updating Ruby to v2.6:

ruby 2.6.0p0 (2018-12-25 revision 66547) [x64-mingw32]

Current gem status:

>gem outdated
bigdecimal (1.4.1 < 1.4.3)

Failure to update digdecimal gem on Win 10 x64 due to MSYS2 not on the system:

>gem update bigdecimal
Updating installed gems
Updating bigdecimal
MSYS2 could not be found. Please run 'ridk install'
or download and install MSYS2 manually from https://msys2.github.io/

Remove BigDecimal.ver

BigDecimal.ver will be deprecated after Ruby 2.5, and should be removed after Ruby 2.6.

How to call `BigDecimal(num)` from C?

Hello, in the mysql2 gem, we convert MySQL datatypes to Ruby datatypes in C space wherever possible for performance reasons. Our code to convert DECIMAL types to Ruby is roughly:

rb_funcall(cBigDecimal, rb_intern("new"), 1, rb_str_new(row[i], fieldLengths[i]));

Because of the new deprecation notice, and the future direction to remove the BigDecimal#new method, I'm adjusting this code, but without success, per brianmario/mysql2#925 (comment)

I think this should work, but so far it does not, and crashes (no backtrace, yet, will see if I can generate one and post it to this ticket).

rb_funcall(rb_cObject, rb_intern("BigDecimal"), 1, rb_str_new(row[i], fieldLengths[i]));

Is there a C interface that I can tap into, or a known method for calling global functions from C?

Thanks!

Inconsistent conversion/treatment of nil

Nil is treated differently for two similar functions:

  • BigDecimal(nil) #=> TypeError (can't convert nil into BigDecimal)
  • nil.to_d #=> 0.0

This is probably as a result of the PR submitted for this closed issue #100 .

Not sure which of the two would be best, as there are benefits in both approaches, but a consistent approach may be desirable here?

Calling new on subclass of BigDecimal returns BigDecimal instance in Ruby 2.6

Hi,

I am running some tests with the newly released Ruby 2.6 and there seems to be a difference in behavior when subclassing BigDecimal. I no longer get an instance of the subclass back when calling <Subclass>.new, instead I get an instance of BigDecimal:

$ rbenv global 2.5.3
$ irb -r bigdecimal
irb(main):001:0> class Foo < BigDecimal; end
=> nil
irb(main):002:0> Foo.new(0).class
=> Foo

$ rbenv global 2.6.0
$ irb -r bigdecimal
irb(main):002:0> class Foo < BigDecimal; end
=> nil
irb(main):003:0> Foo.new(0).class
(irb):3: warning: BigDecimal.new is deprecated; use BigDecimal() method instead.
=> BigDecimal

Is this change in behavior intended? Assuming it is, are there other ways to create a subclass of BigDecimal?

I realize that BigDecimal.new will be removed, so I need to understand my options here. Perhaps subclassing is not the way to go?

Release 1.4.4

  • Backport #138
  • #146
  • Check gem install on Linux
    • Ruby 2.3
    • Ruby 2.4
    • Ruby 2.5
    • Ruby 2.6
  • Check gem install on macOS
    • Ruby 2.3
    • Ruby 2.4
    • Ruby 2.5
    • Ruby 2.6
  • Check gem install on Windows
    • Ruby 2.3
    • Ruby 2.4
    • Ruby 2.5
    • Ruby 2.6
  • Release 1.4.4

bigdecimal/util must require bigdecimal

irb(main):001:0> require 'bigdecimal/util'
=> true
irb(main):002:0> 1.to_d
Traceback (most recent call last):
        3: from /Users/mrkn/.rbenv/versions/2.5/bin/irb:11:in `<main>'
        2: from (irb):2
        1: from /Users/mrkn/.rbenv/versions/2.5.1/lib/ruby/2.5.0/bigdecimal/util.rb:23:in `to_d'
NoMethodError (undefined method `BigDecimal' for 1:Integer)
irb(main):003:0>

Feel confusion about LoadError when require 'bigdecimal/util'

OS: Windows 10
Ruby: 2.5.0 x64 with MSYS2
bigdecimal: 1.4.3

When bigdecimal is loaded before bigdecimal/util:

require 'bigdecimal'
require 'bigdecimal/util'

It will raise LoadError:

uby25-x64/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:130:in `require': 127: ?????????   - C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bigdecimal-1.4.3/lib/bigdecimal/util.so (LoadError)
	from C:/Ruby25-x64/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require'
	from C:/Ruby25-x64/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:34:in `require'
	from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bigdecimal-1.4.3/lib/bigdecimal/util.rb:9:in `<top (required)>'
	from C:/Ruby25-x64/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	from C:/Ruby25-x64/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	from E:/DemoProjects/RubyLearning/chapter_2.rb:2:in `<main>'

However, bigdecimal/util is loaded before bigdecimal will suceess:

require 'bigdecimal/util'
require 'bigdecimal'

So why does this happen? It will make library monetize or money raising LoadError, because in their source codes, bigdecimal is loaded before bigdecimal/util.

BigDecimal should NEVER throw exceptions!!!

BigDecimal should not throw errors. Ever. You guys need to wrap the code in a begin...rescue with a return 0 for all "error" cases. Anything that's not a valid number is 0 or null or NaN or whatever, but this little math function should NOT be halting my code by throwing errors back upstream.

'invalid value for BigDecimal()'
NO! What the hell!? Whose idea was it for a math function to kick up exceptions?

Precision with multiplications and divisions

I would expect BigDecimal to support arbitrary-precision calculation in a way that it does not lose accuracy after a series of multiplications and divisions.

2.1.4 :004 > BigDecimal("3000") / BigDecimal("3600") * BigDecimal("3600")
 => #<BigDecimal:7f9dc244d880,'0.2999999999 9999999988E4',27(36)>
2.1.4 :005 > (BigDecimal("3000") / BigDecimal("3600") * BigDecimal("3600")).to_s
 => "0.29999999999999999988E4"

^ Should I expect to get back 3000 or is it a bug?

2.1.4 :006 > BigDecimal("3000") * BigDecimal("3600") / BigDecimal("3600")
 => #<BigDecimal:7f9dc241d298,'0.3E4',9(36)>
2.1.4 :007 > _.to_s
 => "0.3E4"

^ If it performs multiplication first, it does not involve floating-point calculation and the result is correct as expected.

BigDecimal.ver

Okay, maybe a bit picky, but I was just working with an app with embedded ruby, and I've got several installs testing various ruby configs. Best yet, (at present) they share a gem folder...

Should BigDecimal.ver return the same version as the gem?

I know it's just one more thing to keep track of...

BigDecimal should NEVER throw exceptions!!!

This issue was wrongly closed, so I re-opened it.

BigDecimal should never throw exceptions. Math library function calls should not introduce breaking changes into a codebase.

Incorrect Result in 32 Bit Platforms

Hi, write you here a snipped illustrating a wrong result I am getting. Specs of the two platform used to see the bug are below.

========================
require 'bigdecimal'
BigDecimal.limit(1000)

# ok => 2.718...
n = 1_000_000_000;
((BigDecimal.new(n) + BigDecimal.new(1)) / BigDecimal.new(n))**BigDecimal.new(n)

# gives infinity, not good, it should converge to value E or rise
# an exception if it can't compute it.
n = 1_000_000_000_0;
((BigDecimal.new(n) + BigDecimal.new(1)) / BigDecimal.new(n))**BigDecimal.new(n)
========================

The two 32 platforms in which I can see the bug are
1] ------ in a VMWare Linux Machine Runnning in OSX Host ----------------
$> irb -v
irb 0.9.6(09/06/30)
$> ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [i686-linux]
$> file which ruby
/usr/local/bin/ruby: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=4155341292883d00fd56de2c46abb3f23151c640, not stripped
$> uname -a
Linux foo 3.16.0-4-686-pae #1 SMP Debian 3.16.43-2+deb8u5 (2017-09-19) i686 GNU/Linux
$> cat /etc/debian_version
8.9
2] ----- In a BeagleBone Black -----------------
#> uname -a
Linux bbtest 4.4.91-ti-r133 #1 SMP Tue Oct 10 05:18:08 UTC 2017 armv7l GNU/Linux
#> cat /etc/debian_version
9.2
#> cat /etc/dogtag
BeagleBoard.org Debian Image 2017-10-10
#> ruby -v
ruby 2.3.3p222 (2016-11-21) [arm-linux-gnueabihf]
#> irb -v
irb 0.9.6(09/06/30)
#> file /usr/bin/ruby2.3
/usr/bin/ruby2.3: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=755336ae6067230d52c894c8d91ec82f6402d3ab, stripped

Incorrect documentation for BigDecimal#sign

The documentation for BigDecimal#sign is incorrect. It reads:

Returns a positive value if > 0, a negative value if < 0, and a zero if == 0.

* Returns a positive value if > 0, a negative value if < 0, and a
* zero if == 0.

However, this does not match BigDecimal's behavior:

[1] pry(main)> require 'bigdecimal'
=> true
[2] pry(main)> BigDecimal.new("0").sign
=> 1
[3] pry(main)> BigDecimal.new("-0").sign
=> -1

These values match the BigDecimal::SIGN_XXX constants for signed zeroes, which have the values 1 and -1 (neither of which is zero as #sign seems to document)

BigDecimal regression - to_d inconsistent with other numeric classes

I originally filed this on bugs.ruby-lang.org, not sure if this is a more appropriate place.

As of ruby 2.4.0-rc1, BigDecimal() was changed to raise exceptions on invalid input, which is more consistent with the other numeric types. Unfortunately, String#to_d now also raises errors, which is inconsistent with the other to_* methods (to_i, to_f), which return 0 on error.

Under ruby 2.4.0-rc1:

> require 'bigdecimal'
> require 'bigdecimal/util'
> "invalid".to_d
ArgumentError: invalid value for BigDecimal(): "invalid"
> "invalid".to_i
=> 0
> "invalid".to_f
=> 0.0

Under ruby 2.3.3 or 2.4.0preview3:

> "invalid".to_d
=> #<BigDecimal:55871ca1f808,'0.0',9(9)>
> "invalid".to_i
=> 0
> "invalid".to_f
=> 0.0

There's also a further problem that BigDecimal() still doesn't behave the same as Integer() when given a string with the number at the start:

Under ruby 2.4.0-rc1:

> BigDecimal("2 turtle doves")
=> 0.2e1
> Integer("2 turtle doves")
ArgumentError: invalid value for Integer(): "2 turtle doves"
> Float("2 turtle doves")
ArgumentError: invalid value for Float(): "2 turtle doves"

So BigDecimal is still inconsistent.

Serde feature

An optional serde integration would be nice to have, to avoid having to wrap BigDecimal in a newtype just for implementing (De)serialize.

I'd excpect it to serialize to a string and deserialize from strings and floats.

Is a format `"1.e+00"` invalid in Ruby 2.4.0 or later?

I hava a question.

The string representation accepted as a BigDecimal has become strict with the following commit.

3081a62

% ruby -v
ruby 2.4.0dev (2016-12-13 trunk 57069) [x86_64-darwin13]
% irb
> require "bigdecimal"
> sprintf("%#.0e", 1) #=> "1.e+00"
> BigDecimal("1.e+00") #=> ArgumentError: invalid value for BigDecimal(): "1.e+00"

For example, the sprintf document shows a format like "1.e+00".

https://github.com/ruby/ruby/blob/v2_4_0_rc1/sprintf.c#L354

Is this format ("1.e+00") not recommended as a BigDecimal library anymore?

Thanks.

Error Updating Under Win 10 x64

(hopefully not a duplicate #118 and #119, since this is make-related error)

ruby 2.5.3p105 (2018-10-18 revision 65156) [x64-mingw32]

When I try to update the gem under Win 10 x64 I get this error:

current directory: C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/bigdecimal-1.4.1/ext/bigdecimal/util
C:/tools/ruby25/bin/ruby.exe -r ./siteconf20181225-9440-zwbdav.rb extconf.rb
checking for Windows... yes
creating Makefile

current directory: C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/bigdecimal-1.4.1/ext/bigdecimal/util
make "DESTDIR=" clean
bash.exe: warning: could not find /tmp, please create!

current directory: C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/bigdecimal-1.4.1/ext/bigdecimal/util
make "DESTDIR="
generating util-x64-mingw32.def
bash.exe: warning: could not find /tmp, please create!
compiling util.c
linking shared-object bigdecimal/util.so
x86_64-w64-mingw32-gcc.exe: error: C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/bigdecimal-1.4.1/tmp/x64-mingw32/bigdecimal/2.5.3/bigdecimal.so: No such file or directory
make: *** [Makefile:259: util.so] Error 1

make failed, exit code 2

Inconsistency between String#to_d and String#to_f

String#to_d behaves differently from String#to_f for strings starting with a number that is not followed by whitespace:

require "bigdecimal"
require "bigdecimal/util"

"40.5degree".to_f  # => 40.5
"40.5degree".to_d  # => 0.0

For many other cases they behave in the same way, e.g.:

"40.5 degree".to_f  # => 40.5
"40.5 degree".to_d  # => 0.405e2

"foo".to_f  # => 0.0
"foo".to_d  # => 0.0

"40.5e-2".to_f  # => 0.405
"40.5e-2".to_d  # => 0.405e0

../bigdecimal.so: cannot open shared object file

irb(main):004:0> require 'bigdecimal/util'
Traceback (most recent call last):
       10: from /home/mrkn/.rbenv/versions/2.6/bin/irb:23:in `<main>'
        9: from /home/mrkn/.rbenv/versions/2.6/bin/irb:23:in `load'
        8: from /home/mrkn/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
        7: from (irb):4
        6: from /home/mrkn/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        5: from /home/mrkn/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        4: from /home/mrkn/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bigdecimal-1.4.4.dev/lib/bigdecimal/util.rb:9:in `<top (required)>'
        3: from /home/mrkn/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:34:in `require'
        2: from /home/mrkn/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require'
        1: from /home/mrkn/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `require'
LoadError (../bigdecimal.so: cannot open shared object file: No such file or directory - /home/mrkn/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bigdecimal-1.4.4.dev/lib/bigdecimal/util.so)

Can't install/update on macOS 10.14.2 using rbenv & ruby 2.5.3

gem update
Updating installed gems
Updating bigdecimal
Fetching: bigdecimal-1.4.0.gem (100%)
Building native extensions. This could take a while...
ERROR:  Error installing bigdecimal:
	ERROR: Failed to build gem native extension.

    current directory: /Users/jesseatkinson/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bigdecimal-1.4.0/ext/bigdecimal
/Users/jesseatkinson/.rbenv/versions/2.5.3/bin/ruby -r ./siteconf20181223-54536-li5aao.rb extconf.rb
checking for labs() in stdlib.h... yes
checking for llabs() in stdlib.h... yes
checking for finite() in math.h... yes
checking for isfinite() in math.h... no
checking for struct RRational in ruby.h... no
checking for rb_rational_num() in ruby.h... yes
checking for rb_rational_den() in ruby.h... yes
checking for rb_array_const_ptr() in ruby.h... yes
checking for rb_sym2str() in ruby.h... yes
creating Makefile

current directory: /Users/jesseatkinson/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bigdecimal-1.4.0/ext/bigdecimal
make "DESTDIR=" clean
make[1]: *** No rule to make target `../../lib/bigdecimal.rb', needed by `Makefile'.  Stop.

current directory: /Users/jesseatkinson/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bigdecimal-1.4.0/ext/bigdecimal
make "DESTDIR="
make[1]: *** No rule to make target `../../lib/bigdecimal.rb', needed by `Makefile'.  Stop.

make failed, exit code 2

Gem files will remain installed in /Users/jesseatkinson/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bigdecimal-1.4.0 for inspection.
Results logged to /Users/jesseatkinson/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-18/2.5.0-static/bigdecimal-1.4.0/gem_make.out

I've completely uninstalled and re-installed rbenv & ruby 2.5.3. Any ideas why this is still failing?

Strings with commas errors

Can someone explain the logic behind:

> BigDecimal.new('2,30').to_f
=> 2.0
> BigDecimal.new('19,000.00').to_f
=> 19

Shouldn't these raise?

pathname must not be used in extconf.rb

$ cd path/to/ruby-trunk
$ make install V=1
...(snip)...
./miniruby -I/Users/mrkn/src/github.com/ruby/ruby/lib -I. -I.ext/common  /Users/mrkn/src/github.com/ruby/ruby/ext/extmk.rb --make='/Applications/Xcode_10.app/Contents/Developer/usr/bin/make' \
                --command-output=ext/bigdecimal/exts.mk --dest-dir="" --extout=".ext" --mflags="" --make-flags="V=1" --gnumake=yes --extflags="" --make-flags="MINIRUBY='./miniruby -I/Users/mrkn/src/github.com/ruby/ruby/lib -I. -I.ext/common '" --extstatic  \
                -- configure ext/bigdecimal
/Users/mrkn/src/github.com/ruby/ruby/ext/bigdecimal/extconf.rb
Traceback (most recent call last):
        8: from /Users/mrkn/src/github.com/ruby/ruby/ext/extmk.rb:564:in `<main>'
        7: from /Users/mrkn/src/github.com/ruby/ruby/ext/extmk.rb:564:in `each'
        6: from /Users/mrkn/src/github.com/ruby/ruby/ext/extmk.rb:568:in `block in <main>'
        5: from /Users/mrkn/src/github.com/ruby/ruby/ext/extmk.rb:210:in `extmake'
        4: from /Users/mrkn/src/github.com/ruby/ruby/lib/mkmf.rb:331:in `open'
        3: from /Users/mrkn/src/github.com/ruby/ruby/ext/extmk.rb:214:in `block in extmake'
        2: from /Users/mrkn/src/github.com/ruby/ruby/ext/extmk.rb:214:in `load'
        1: from /Users/mrkn/src/github.com/ruby/ruby/ext/bigdecimal/extconf.rb:3:in `<top (required)>'
/Users/mrkn/src/github.com/ruby/ruby/ext/bigdecimal/extconf.rb:3:in `require': cannot load such file -- pathname (LoadError)
make[1]: *** [ext/bigdecimal/exts.mk] Error 1
make: *** [exts.mk] Error 2

Unexpected behaviour if `BigDecimal.new("NaN")` is used as a key of hash

$ ruby -v
ruby 2.4.0preview3 (2016-11-07 trunk 56661) [x86_64-darwin14]
irb(main):001:0> require "bigdecimal"
=> true
irb(main):002:0>  nan = BigDecimal.new("NaN")
=> #<BigDecimal:7ff5f213bad8,'NaN',9(9)>
irb(main):003:0> h = {nan => 1000}
=> {#<BigDecimal:7ff5f213bad8,'NaN',9(9)>=>1000}
irb(main):004:0> h[BigDecimal.new("NaN")]
=> nil
irb(main):005:0> h[nan]
=> 1000

I expected h[nan] to return nil, because nan.eql? nan returns false.
This is because hash compare pointers first.
https://github.com/ruby/ruby/blob/v2_4_0_preview3/hash.c#L99-L102

BigDecimal nil inconsistency with numeric classes

Hello, I'm trying to migrate my app Floats to BigDecimals, but I'm finding it inconsistent with other numeric classes.

nil.to_i # => 0
nil.to_f # => 0.0
nil.to_d # => undefined method `to_d' for nil:NilClass

Would you be interested in me sending a PR for this case? I'd be happy to help

[Bug-13331] Inconsistent conversion of Float into Decimal

https://bugs.ruby-lang.org/issues/13331

One would reasonably expect the equality 1.to_d * f == f.t_d to hold for every Float value f, i.e. multiplying by DigDecimal's unit can be viewed as an alternative way of casting Float into Decimal; or simply one could expect that BigDecimal#* should always invoke Float#to_d on it's argument. Yet for some Floats (e.g. 64.4) the results differ, as showed in the provided script. This can cause a bug in some application contexts.

Originally I asked about that on Stackoverflow:
http://stackoverflow.com/questions/40472933/inconsistent-conversion-of-float-into-decimal-in-ruby/40473007

See the comprehensive answer by Stefan who points out that it is due to different precisions being used in Float#to_d and BigDecimal#*.

Gem bigdecimal-1.4.0 install error

Linux Debian 8
Apache 2.4
Ruby 2.5.3, 2.3.8

During an installation bigdecimal-1.4.0 running by 'gem update' is occurred error:

Updating installed gems
Updating bigdecimal
Fetching bigdecimal-1.4.0.gem
Building native extensions. This could take a while...
ERROR:  Error installing bigdecimal:
        ERROR: Failed to build gem native extension.

    current directory: /home/ruby/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/bigdecimal-1.4.0/ext/bigdecimal
/home/ruby/.rbenv/versions/2.3.8/bin/ruby -I /home/ruby/.rbenv/versions/2.3.8/lib/ruby/site_ruby/2.3.0 -r ./siteconf20181224-26637-iv5fbs.rb extconf.rb
checking for labs() in stdlib.h... yes
checking for llabs() in stdlib.h... yes
checking for finite() in math.h... yes
checking for isfinite() in math.h... no
checking for struct RRational in ruby.h... no
checking for rb_rational_num() in ruby.h... yes
checking for rb_rational_den() in ruby.h... yes
checking for rb_array_const_ptr() in ruby.h... yes
checking for rb_sym2str() in ruby.h... yes
creating Makefile

current directory: /home/ruby/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/bigdecimal-1.4.0/ext/bigdecimal
make "DESTDIR=" clean
make: *** Нет правила для сборки цели «../../lib/bigdecimal.rb», требуемой для «Makefile».  Останов.

current directory: /home/ruby/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/bigdecimal-1.4.0/ext/bigdecimal
make "DESTDIR="
make: *** Нет правила для сборки цели «../../lib/bigdecimal.rb», требуемой для «Makefile».  Останов.

make failed, exit code 2

Gem files will remain installed in /home/ruby/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/bigdecimal-1.4.0 for inspection.
Results logged to /home/ruby/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0-static/bigdecimal-1.4.0/gem_make.out

String#to_d does not return partially parsed results for trailing decimal

Hi! We've been using Ruby 2.3 for a while and are trying to upgrade to Ruby 2.5. One issue that I'm noticing is that, perhaps because of the fix to #51 (in #55), the behavior of String#to_d is different than it used to be when the string starts with a number but is not a complete number. The behavior is now inconsistent with the behavior of String#to_f

I.e.

require 'bigdecimal'
require 'bigdecimal/util'

'1.'.to_d
=> 0.0 # Returns 0.0, but used to return 1.0
'1.'.to_f
=> 1.0

The documentation still says:

initial
The initial value, as an Integer, a Float, a Rational, a BigDecimal, or a String.
If it is a String, spaces are ignored and unrecognized characters terminate the value.

This works okay if I pass in things like "1 pizza" etc, but I guess this specific case of a number with a decimal and nothing after the decimal no longer works, which is kind of unfortunate for my specific use case.

'1.'.to_d == '1.'.to_f
# returns true on 2.3, false on 2.5

I'm on Ruby 2.5.5 with BigDecimal 1.3.4.

Thanks!

active support cannot load bigdecimal - gets an undefined symbol error

Steps to reproduce

Installed Ruby on an archlinux / manjaro environment ( up to date ) in a virtual machine
Installed the rails gem with a gem install rails
Tried a require 'rails' in both irb and a file

Expected behavior

No issues loading the gem

Actual behavior

The gem cannot be loaded. There seems to be an issue when trying to load the bigdecimal gem.
I have no issue when trying to load the bigdecimal gem directly.
The error is the following :

irb(main):001:0> require 'rails'
Traceback (most recent call last):
       16: from /home/matthieu/.gem/ruby/2.5.0/gems/railties-5.2.2/lib/rails/configuration.rb:4:in `<top (required)>'
       15: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
       14: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
       13: from /home/matthieu/.gem/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/core_ext/object.rb:13:in `<top (required)>'
       12: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
       11: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
       10: from /home/matthieu/.gem/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/core_ext/object/json.rb:8:in `<top (required)>'
        9: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
        8: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
        7: from /home/matthieu/.gem/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/core_ext/big_decimal/conversions.rb:4:in `<top (required)>'
        6: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
        5: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
        4: from /home/matthieu/.gem/ruby/2.5.0/gems/bigdecimal-1.4.2/lib/bigdecimal/util.rb:9:in `<top (required)>'
        3: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:39:in `require'
        2: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
        1: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `require'
LoadError (/home/matthieu/.gem/ruby/2.5.0/gems/bigdecimal-1.4.2/lib/bigdecimal/util.so: undefined symbol: rmpd_util_str_to_d - /home/matthieu/.gem/ruby/2.5.0/gems/bigdecimal-1.4.2/lib/bigdecimal/util.so)

System configuration

Rails version: rails (5.2.2)
Ruby version: Ruby 2.5.3p105

I am at a loss on what to do to solve this issue could you please help me ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.