Coder Social home page Coder Social logo

Comments (6)

schungx avatar schungx commented on July 23, 2024 1

The use case is actually exposing a function for users to call. If users put in a huge exponent, they may not expect the program to be running for 100 seconds and will think the program has hung. An error would be a much better solution in my case.

Thus, I'll limit the max exponent for users. That would make it more foolproof.

On your side I'd suggest a note on the API saying that it may take a long time to run if the exponent is large, as it may not be completely expected.

Thanks!

from rust-decimal.

Tony-Samuels avatar Tony-Samuels commented on July 23, 2024

It's certainly slow, but I wouldn't say it takes forever. As an example:

    let base = dec!(0.99999999999999);
    let exp = dec!(147728940);
    println!("Starting");
    let result = base.powd(exp);
    println!("{result}");
    let second_result = base.checked_powd(exp).unwrap();
    println!("{second_result}");

The powd's result is printed about 10 seconds after the previous message, and checked_powd takes the same amount of time. Increasing the exponent by a factor of ten again makes it take 100 seconds instead, so (with admittedly few data points) this seems linear with the exponent value rather than exponential.

I don't suppose you could explain a little more about your use case? What are you attempting to do where you want to attempt to calculate an exponential, giving up if it takes too long? Maybe there's another solution that would work better.

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.