Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

float parser #14

Closed
pjfanning opened this issue Apr 25, 2022 · 4 comments
Closed

float parser #14

pjfanning opened this issue Apr 25, 2022 · 4 comments

Comments

@pjfanning
Copy link
Contributor

pjfanning commented Apr 25, 2022

Hi - thanks for all the great work on the double parser. I've been experimenting with it for possible inclusion in jackson-core.

Parsing floats using the double parser is also much faster than using Float.parseFloat but unfortunately casting doubles to floats can often give you different result from plain Float.parseFloat.

Would it be possible to consider also supporting a dedicated float parser?

An example is 7.006492321624086e-46 which Float.parseFloat returns as 1.4E-45 but using FastDoubleParser:

        double dbl = FastDoubleParser.parseDouble("7.006492321624086e-46");
        System.out.println("double=" + dbl); //7.006492321624085E-46
        System.out.println("float=" + (float)dbl); //0.0
@lemire
Copy link
Contributor

lemire commented Apr 25, 2022

Note that the C# equivalent has such functions (float support). See https://github.com/CarlVerret/csFastFloat

@wrandelshofer
Copy link
Owner

I have now refactord the code a bit, and added a new class FastFloatParser.

It should do now what you want. 😅

% jshell --module-path out --add-modules ch.randelshofer.fastdoubleparser
|  Welcome to JShell -- Version 18.0.1
|  For an introduction type: /help intro

jshell> import ch.randelshofer.fastdoubleparser.*

jshell> FastFloatParser.parseFloat("7.006492321624086e-46")
$2 ==> 1.4E-45

jshell> 

@pjfanning
Copy link
Contributor Author

Thanks @wrandelshofer - I'll try it out over next few days

@pjfanning
Copy link
Contributor Author

I'll close this - so far, looks good to me - thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants