Comments (6)
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.
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)
- Disabled optional weak dependencies like "borsh" are pulled in with default-features HOT 2
- Feature request: `Decimal::is_integer()` HOT 3
- Update borsh crate due to a security vulnerability issue. HOT 4
- Can't deserialize with `float_option` when null in an internally tagged enum HOT 3
- `trunc_with_scale` issue HOT 4
- `serde-arbitrary-precision` without `serde-float` HOT 7
- `is_integer` has BUG HOT 1
- How to serialize Decimal and still keep the results in order (bitwise comparison) HOT 3
- Serialization V2 - brainstorming HOT 1
- feature request: JSON schema support via https://github.com/GREsau/schemars HOT 1
- Feature Request: Support wasm_bindgen for Decimal
- rlp (de)serialization? HOT 2
- Rust Decimal: Request for additional repository Owner/Collaborator(s) HOT 1
- Rescaling a value with significant scale 28 to scale 29 creates a value with scale 29 and overflows on subtraction HOT 1
- Support for mongo HOT 2
- To f64 losing accuracy for `100000.000000000000000000` HOT 1
- Scaling string representation differs from dividing by 10^x HOT 4
- too rubbish to called rust decimal HOT 3
- Scale changes unexpectedly after operations HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-decimal.