Giter Site home page Giter Site logo

Comments (2)

dnsl48 avatar dnsl48 commented on July 29, 2024

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.

Enyium avatar Enyium commented on July 29, 2024

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)

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.