Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.0.to_d returns negative zero in jruby-9.2.7.0 #5723

Closed
ikonomov17 opened this issue May 2, 2019 · 3 comments

Comments

@ikonomov17
Copy link

commented May 2, 2019

Environment

  • JRuby version (jruby -v) and command line (flags, JRUBY_OPTS, etc)
    • jruby 9.2.7.0 (2.5.3) 2019-04-09 8a269e3 Java HotSpot(TM) 64-Bit Server VM 25.192-b12 on 1.8.0_192-b12 +jit [darwin-x86_64]
  • Operating system and platform (e.g. uname -a)
    • MacOS Mojave 10.14.4

Expected Behavior

  • Using ruby-2.5.3, when I am trying to convert 0.0 to a BigDecimal I would expect to receive a zero without a negative sign, as shown in the example below.
>>  require "bigdecimal"
=> true
>>  require "bigdecimal/util"
=> true
>> 0.0.to_d
=> 0.0
>> BigDecimal(0.0, 0)
=> 0.0

Actual Behavior

  • When I am using jruby-9.2.7.0 and try to convert 0.0 to a BigDecimal I receive a negative zero.
>> require "bigdecimal"
=> true
>> require "bigdecimal/util"
=> true
>> 0.0.to_d
=> -0.0
>> BigDecimal(0.0, 0)
=> -0.0
@headius

This comment has been minimized.

Copy link
Member

commented May 2, 2019

It's sometimes amazing the things that go unreported! Shouldn't be hard to fix.

@headius

This comment has been minimized.

Copy link
Member

commented May 2, 2019

I see the problem...the code compares the value with -0.0 to determine sign, but -0.0 == 0.0 so it's always coming out negative.

@headius headius closed this in da827f2 May 2, 2019

headius added a commit that referenced this issue May 2, 2019

@headius headius added this to the JRuby 9.2.8.0 milestone May 2, 2019

@ikonomov17

This comment has been minimized.

Copy link
Author

commented May 3, 2019

Great, thanks for solving it that quickly!

eregon added a commit to ruby/spec that referenced this issue May 28, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.