Coder Social home page Coder Social logo

delayTime rounding about flanimatedimage HOT 6 CLOSED

flipboard avatar flipboard commented on August 20, 2024
delayTime rounding

from flanimatedimage.

Comments (6)

raphaelschaad avatar raphaelschaad commented on August 20, 2024

Great catch. Curious that NSNumber doesn't do "the right thing" here.

We could use a small enough epsilon to let the minimum slide (but not much beyond that) e.g. by defining const CGFloat kEpsilon = 0.00001; or using the constant FLT_EPSILON. But I never liked mocking "manually" with float comparisons.

Any suggestions?

from flanimatedimage.

pronebird avatar pronebird commented on August 20, 2024

What if we clamp kDelayTimeIntervalMinimum to float so both types match when comparing? I just tested this and it works fine.

if ([delayTime compare:[NSNumber numberWithFloat:kDelayTimeIntervalMinimum]] == NSOrderedAscending) {
    // ...
}

Fun stuff to read: https://github.com/opensource-apple/CF/blob/master/CFNumber.c#L1347

from flanimatedimage.

raphaelschaad avatar raphaelschaad commented on August 20, 2024

Interesting, so if I interpret the Core Foundation code correctly, all NSNumber does is upcasting floats to doubles when comparing.

If we go the route of "normalizing" by down casting to float -- which is what I tried to avoid by just letting NSNumber do "the right thing" --, it seems more straight-forward to just do it by (float) kDelayTimeIntervalMinimum and then comparing with less than.

Does that capture the case with your test GIF?

from flanimatedimage.

pronebird avatar pronebird commented on August 20, 2024

That should work.

from flanimatedimage.

raphaelschaad avatar raphaelschaad commented on August 20, 2024

Could you verify it addresses the case with your specific GIF? If yes, would you like to open a pull request with the change? I'm happy to merge it in.

Let me know if you'd prefer me doing it.

from flanimatedimage.

pronebird avatar pronebird commented on August 20, 2024

Sure, let me check. I can prepare PR, it's not a problem.

On Friday, July 18, 2014, Raphael Schaad [email protected] wrote:

Could you verify it addresses the case with your specific GIF? If yes,
would you like to open a pull request with the change? I'm happy to merge
it in.

Let me know if you'd prefer me doing it.


Reply to this email directly or view it on GitHub
#20 (comment)
.

from flanimatedimage.

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.