Giter VIP home page Giter VIP logo

Comments (4)

gvraams avatar gvraams commented on July 30, 2024

Problem is only with "9.8".

9.7.abs <= BigDecimal('9.7')
=> true

from bigdecimal.

mrzasa avatar mrzasa commented on July 30, 2024

It's likely related to the precision of converting floats to BigDecimal, see below:

# It's not only with `#abs`, also without it
[40] pry(main)> 9.8 <= BigDecimal('9.8')
=> false

# when we calculate the delta we see a small, but non-zero result
[41] pry(main)> 9.8.to_d - BigDecimal('9.8')
=> 0.1e-14

# if we use the `Float::DIG` constant it's OK
[42] pry(main)> 9.8.to_d(15) - BigDecimal('9.8')
=> 0.0

# if we use the `Float::DIG+1` constant it's no OK (the new default) after https://github.com/ruby/bigdecimal/commit/aa536cd4b585ff6045cf91f396bc3eef993b91f2
[43] pry(main)> 9.8.to_d(16) - BigDecimal('9.8')
=> 0.1e-14

# because of how the representation looks like
[44] pry(main)> 9.8.to_d(16) 
=> 0.9800000000000001e1

seems to be related to aa536cd

from bigdecimal.

mrzasa avatar mrzasa commented on July 30, 2024

It's fixed in the newest version of the gem:

[8] pry(main)> 9.8.abs <= BigDecimal('9.8')
=> true
[9] pry(main)> BigDecimal::VERSION
=> "3.1.2"

from bigdecimal.

gvraams avatar gvraams commented on July 30, 2024

@mrzasa - Thank you for your response and investigation.

from bigdecimal.

Related Issues (20)

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.