Git Product home page Git Product logo

Comments (6)

paupino avatar paupino commented on August 21, 2024

Agreed. Will look into this one. Thanks for the example!

from rust-decimal.

paupino avatar paupino commented on August 21, 2024

So there is definitely an underflow happening with addition whereby the last bit exceeds the allocated 96 bit storage space at that scale. While I could panic, I feel like this should rather work and instead round to 8314.622985886882835357072470.

If I did this and instead provided checked functions would this help your case?

from rust-decimal.

paupino avatar paupino commented on August 21, 2024

Looking at some other libraries output it appears that rounding (or losing precision) in this case is the de facto. For consistency I think this is what I'll implement however do want to consider functions and cases whereby this loss of precision is unacceptable.

from rust-decimal.

snd avatar snd commented on August 21, 2024

rounding the last decimal places and loosing a tiny bit of precision sounds like a good solution for cases like this.

i can imagine there are users that don't want to silently loose even a tiny bit of precision and would like to know when overflow/rounding occurs. the checked functions sound like a good solution.

how do we ensure that there are no further cases like this, where an overflow silently results in completely wrong results? you describe the crate as suitable for financial calculations. in financial applications errors like this could have pretty bad consequences.

i'd have more confidence in the crate if it tested common math invariants using something like https://github.com/BurntSushi/quickcheck. happy to add some quickcheck tests if you agree.

from rust-decimal.

paupino avatar paupino commented on August 21, 2024

QuickCheck looks interesting - I'd be happy to get this included. How would you intend on utilizing it?

from rust-decimal.

paupino avatar paupino commented on August 21, 2024

I'm going to pull implementing QuickCheck into a new issue so I can close this one once it's fixed.

from rust-decimal.

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.