Code Monkey home page Code Monkey logo

Comments (7)

bcmyers avatar bcmyers commented on July 30, 2024 1

Yes - I had always planned to add floating point support to num-format, but it's a bit more complicated than integers. I'd like to read and (at least partially) understand some of the following kind of stuff before I get started (just a sample of various stuff on the topic that's out there):

But if inferno needs it, I'd be happy to prioritize the feature!

Doing a very naive implementation, by the way, would be super easy, but it would be just that, a very naive implementation. But if you wanted a temporary stop-gap feature added, I could do the naive version quickly while I work on implementing a faster algorithm for later release.

from inferno.

jasonrhansen avatar jasonrhansen commented on July 30, 2024

I did an initial implementation of this and realized that the output sometimes differs between my version and the Perl version because of differences in the way floating point numbers are rounded when formatting to a string compared to calling round on an f64.

712.5f64.round() as usize results in 713, but print!("{:.0}", 712.5); prints 712.

The Perl version formats the samples like this:

my $samples = sprintf "%.0f", ($etime - $stime) * $factor;

But our version is using num_format, which doesn't support formatting floating point values. Currently I'm doing this before formatting:

let samples = ((frame.end_time - frame.start_time) as f64 * opt.factor).round() as usize;

Do we want to come up with a way to get the sample counts to match the Perl version in every case, or should we not worry about it?

from inferno.

jonhoo avatar jonhoo commented on July 30, 2024

I think we specifically need the result to not be a usize, since factor may be something like 0.01. @bcmyers any plans to add support for floating point numbers to num-format?

from inferno.

jasonrhansen avatar jasonrhansen commented on July 30, 2024

The Perl version formats the samples in the end without the fractional part. Are you saying you want to diverge from this behavior? If so, how many decimal places would we want to show?

from inferno.

jonhoo avatar jonhoo commented on July 30, 2024

Ohh, you're entirely right! I misread that part of the Perl code. I think what we want here is f64::floor or f64::trunc (not sure how they're different), both of which would exactly match the Perl version. Let's continue discussion in #65.

from inferno.

jonhoo avatar jonhoo commented on July 30, 2024

@bcmyers thanks, I appreciate that, but from the discussion above I think it's fine for us to just convert to an integer and then format, as that's what the Perl implementation is doing :)

from inferno.

bcmyers avatar bcmyers commented on July 30, 2024

Sounds good.

from inferno.

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.