Skip to content

Use a safer method for detecting negative zero - #3094

Open
daveorourke wants to merge 1 commit into
JamesNK:masterfrom
daveorourke:fixDivideByZeroException
Open

Use a safer method for detecting negative zero#3094
daveorourke wants to merge 1 commit into
JamesNK:masterfrom
daveorourke:fixDivideByZeroException

Conversation

@daveorourke

@daveorourke daveorourke commented Jan 19, 2026

Copy link
Copy Markdown

Fixes #2869.

The prior method would throw a DivideByZeroException on systems where the _EM_ZERODIVIDE floating point exception was enabled.

The changes in this PR are just a safer implementation of the changes in #2777 and are covered by those same tests.

Note: I tried to add a test for #2869, but changing the _EM_ZERODIVIDE flag with _controlfp was affecting other tests due to the changing of global state and the parallel execution of the tests. I tried several different test methods before giving up on using _controlfp. I also didn't see any other use of interop (P/Invoke) in the tests, so I wasn't sure you'd accept that anyway.

Even without the additional test, I think these changes are very straightforward and would resolve the above issue, preserving all existing functionality.

The prior method would throw a DivideByZeroException on systems where the _EM_ZERODIVIDE floating point exception was enabled.  See JamesNK#2869.
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

Successfully merging this pull request may close these issues.

Divide by zero exception in Newtonsoft.Json.Utilities.BoxedPrimitives.Get() method

1 participant