question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change ParserBase to track floats independently from doubles

See original GitHub issue

It seems like in some cases, casting a double to a float may result in a slightly different answer than parsing the original number string using Float.parseFloat.

This code in ParserBase (jackson-core) may be contributing to an issue that @plokhotnyuk described with parsing 1.199999988079071 as a float.

    @Override
    public float getFloatValue() throws IOException
    {
        double value = getDoubleValue();
        /* 22-Jan-2009, tatu: Bounds/range checks would be tricky
         *   here, so let's not bother even trying...
         */
        /*
        if (value < -Float.MAX_VALUE || value > MAX_FLOAT_D) {
            _reportError("Numeric value ("+getText()+") out of range of Java float");
        }
        */
        return (float) value;
    }

From my testing, it seems that casting doubles to floats may not get the same result as parsing the text representation directly with Float.parseFloat(String).

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
pjfanningcommented, Apr 26, 2022

@cowtowncoder I added https://github.com/FasterXML/jackson-databind/pull/3470 - it shows the issue that @plokhotnyuk reported. Would you be able to take a look?

0reactions
cowtowncodercommented, Jun 20, 2022

I think this was indeed resolved via #757, closing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ParserBase (Jackson-core 2.12.0 API) - FasterXML
Intermediate base class used by all Jackson JsonParser implementations. Contains most common things that are independent of actual underlying input source.
Read more >
Replace all floats with doubles - java - Stack Overflow
Is it possible to use some construct to replace all floats with doubles (or the opposite) without refactoring?
Read more >
IO tools (text, CSV, HDF5, …) — pandas 1.5.2 documentation
Specifies which converter the C engine should use for floating-point values. The options are None for the ordinary converter, high for the high-precision ......
Read more >
Changelog — Python 3.11.1 documentation
__set_format__() method to float.__setformat__() to fix a typo introduced in Python 3.7. The method is only used by test_float. Patch by Victor Stinner....
Read more >
XC16 and printf of floats and doubles << SOLVED >>
Thanks for the suggestion. I had already tried casting the variables to double without success. I tried, as you suggested, changing the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found