Comments (4)
@tiatomee thanks for reporting that again.
I've published the release 0.7.0 that includes the patch for calc_precision
.
I also added some more docs for the Decimal precision methods. Hope this helps. If not, please feel free to reopen this issue (or create another one).
from fraction.
That works perfectly fine, thank you very much! 👍
from fraction.
Hi, thanks for reporting that!
Sometimes get_precision() does not reflect the actual precision currently used
That's a utility function that merely returns the current precision which the Decimal instance carries internally. That precision is usually calculated on initialisation and is mainly used for representation purpose (not for calculations). E.g. for formatting functions to decide how many digits to show.
using calc_precision() updates this. However this function never terminates for 1 / 3.
Yes, this function's purpose is to calculate the precision, but for irrational numbers that obviously not going to work.
I guess one way to address that would be to add an optional argument to calc_precision
, that would limit the max possible precision. If you don't have any other ideas how to approach that, I guess we could roll out a patch to address this. PRs are welcome, but if you don't have time, I'll make a patch sometime this weekend.
from fraction.
However this function never terminates for 1 / 3
Digging a bit deeper into the code, I found out what exactly is happening there. In fact, it terminates, because it performs checked math in there https://github.com/dnsl48/fraction/blob/master/src/decimal/mod.rs#L813
However, the problem is that for BigDecimal
we use usize
to store precisions, and this type has too high max value. The computation just takes forever.
That does not happen for simple Decimal
which uses u8
to represent precision, so calc_precision
just returns 255
for irrationals.
I'm preparing a patch so that calc_precision
can receive a limiting max_precision
argument. If None
is given, then it would keep calculation until it reaches the exact precision or the capacity of the precision type (same what it does right now).
from fraction.
Related Issues (20)
- Add better unicode support (Fraction slash/division slash) HOT 8
- eligible for funding via thanks.dev HOT 2
- Completing implemention of `identities` module from `num_traits` HOT 3
- Upgrade postgresql support to 0.18.x
- FromStr trait support + Parse fractions HOT 4
- How to convert to `f32` and `f64` numeric types HOT 1
- .pow() and .root() functions for fraction types HOT 3
- Serde support? HOT 2
- Fraction::from_str can fail with overflow if fractional part ends with too many zeroes HOT 3
- Weird huge values when getting the denominator of a fraction HOT 9
- Serialization support for DynaInt HOT 1
- Error: trait bounds other than `Sized` on const fn parameters are unstable HOT 2
- What does it mean that a value cannot be represented by `Ratio<T>`? HOT 2
- Fraction ceil and floor round negative fraction "the wrong way" HOT 1
- how do you conver a GenericFraction into a float? HOT 5
- Is there a list of methods that floats have that aren't impled for fractions HOT 2
- Do not simplify fractions HOT 1
- How should I handle consts? HOT 1
- Add From for f64 and f32 HOT 6
- Trait bounds were not satisfied with nalgebra HOT 2
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 fraction.