Giter VIP home page Giter VIP logo

Comments (4)

alkis avatar alkis commented on May 26, 2024

Unfortunately the underlying API does not support these ops so it is not easy to add. If you can provide implementations I would be happy to review them.

That aside why do you think d128 is going to be accurate? Is there something specific about sin/cos/tan that make them more accurate when arithmetic is done in decimal arithmetic and not binary? Perhaps you are looking for an arbitrary precision library?

from decimal.

mmstick avatar mmstick commented on May 26, 2024

I've already gone ahead and switched the calculate crate to using d128, instead of f64, and it is more accurate. 0.1 * 0.1 actually equals 0.01, and not 0.010000000000000002. The bigdecimal crate is much further behind this one, so it's not an option at this time.

from decimal.

Benjamin-L avatar Benjamin-L commented on May 26, 2024

Decimal floating point suffers from the same rounding issues as binary floating point. It's just that the decimal rounding issues tend to line up with how humans do things by hand. This doesn't mean that decimal floating point doesn't have surprising results. For example:

println!("{}", d128!(3.0) * (d128!(1.0) / d128!(3.0)));

outputs 0.9999999999999999999999999999999999.

from decimal.

tari avatar tari commented on May 26, 2024

I think trigonometric functions would be best implemented in some other crate, since exactly what is required is strongly dependent on the application's needs for accuracy. It seems better if this crate remains a fairly thin binding to decNumber.

I've been looking into this for one of my own applications but haven't arrived at any particular conclusions for the best way to implement trig functions in terms of d128 (I am by no means an expert numeric analyst!). A Taylor series approximation is pretty easy to implement but might be very costly, and I suspect a different polynomial approximation would perform better. Iterative approximation (CORDIC) seems decent but I suspect it's not significantly more performant than implementations that are expressed in terms of multiplication because this library can take advantage of hardware multipliers to a certain degree.

from 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.