Comments (5)
I've taken a further look and am going to change approach slightly. Returning the overflowing bit is relatively easy however there is not much that can be done with it. I think a much more gracious solution is to round the number upon rescaling - namely because it can't be represented in greater detail. In the example above, 0.6386554621848739495798319328
should be scaled down to 0.638655462184873949579831933
since the alternative can't be scaled up without overflowing giving a final result of 12.453781512605042016806722690
. This seems consistent with other libraries.
from rust-decimal.
I think a much more gracious solution is to round the number upon rescaling - namely because it can't be represented in greater detail. In the example above, 0.6386554621848739495798319328 should be scaled down to 0.638655462184873949579831933 since the alternative can't be scaled up without overflowing giving a final result of 12.453781512605042016806722690.
Sounds good! Thanks @paupino for having a look and also for providing details and reasoning 👍
from rust-decimal.
Out of curiosity, for a consistent behavior, couldn't you round to the max possible precision in the multiplication case as well, instead of giving a panic
?
Lines 1811 to 1817 in 7a3728a
(I've already encountered this panic multiple times)
from rust-decimal.
Yes; good catch. Let’s open a new ticket for this case and I’ll see if I can get to it today - I believe the fix should be relatively straight forward. If possible, can you provide some failure cases for this?
from rust-decimal.
Issue created for the multiplication case at #96.
from rust-decimal.
Related Issues (20)
- 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
- checked_powd takes exponentially long time to complete HOT 6
- Scale changes unexpectedly after operations HOT 3
- 1.34.0 breaks with cyclic dependency when installed with "macros" feature HOT 4
- Deserializing `Decimal`s from Postgres using the `db-postgres` feature can lead to invalid `Decimal` instances HOT 4
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.