Comments (2)
Hi @Enyium,
the FromPrimitive trait is re-imported from the num_traits crate. The documentation piece you are referring to is sourced from there.
Ratio type is also re-imported from the num_rational crate.
This crate provides GenericFraction, which implements From<f64>
.
I did a few tests and transformed your explanation into the following doc comment for my Fps::from_f64() function:
sorry, I am not sure what you mean exactly, but ideally the method shouldn't panic. Semantically the method should return None if cannot convert into the relevant type.
from fraction.
Ratio type is also re-imported from the num_rational crate. This crate provides GenericFraction, which implements
From<f64>
.
Thanks for the referral. Naturally I must use this crate then. I'm settling the matter with its authors.
sorry, I am not sure what you mean exactly
I'd like to specify in my API docs when exactly the method Fps::from_f64()
can fail, so a lib user knows how things stand. But that depends on when my deps can fail.
ideally the method shouldn't panic. Semantically the method should return None if cannot convert into the relevant type.
To cite a Reddit comment:
if your library is the source of a panic, then one of the following should be true:
- Your library has a bug.
- Your library documents a precondition of a public API item that, when not met, causes a panic. Therefore, the user of your library has misused your library, and their code has a bug.
My thought was: Frame rates already become nonsensical after values of 200. A lib user could cap the input, from whereever it's sourced, to, e.g., 100_000
or something lower. A frame rate of 0xffff_ffff
would be insane. The high-speed camera record lies at 1_160_000
fps, which is still well below 0xffff_ffff
. But high-speed camera videos are always played back at much lower frame rates, and will also be stored in video files with sensible frame rates.
But since an f64
can be invalid in more ways than just being extraordinarily large, I proceeded to return an Option<...>
.
from fraction.
Related Issues (20)
- cargo check: Trait objects without an explicit `dyn` are deprecated HOT 1
- Allow usage with summing iterators HOT 2
- Why not implement num_traits::Real instead? HOT 3
- Overflow with small number of multiplication HOT 8
- Using `calc_precision` on `1 / 3` does not terminate HOT 4
- Initialization of Decimal without str? HOT 8
- Why no `fraction::Decimal::default()` ? HOT 2
- no-std support HOT 1
- `divide_to_string` panics on negative dividend HOT 2
- 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
- Fraction ceil and floor round negative fraction "the wrong way" HOT 1
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.