Fix: -Wfloat-conversion error in print_number on MinGW - #1061
Open
coveyjorjet wants to merge 1 commit into
Open
Conversation
isnan/isinf in MinGW-w64's math.h dispatch to float-typed helpers, so passing a double triggers -Wconversion/-Wfloat-conversion errors under -Werror. Replace the call with a pure C89 IEEE-754 check on double only: (d != d) detects NaN, and comparisons against DBL_MAX detect infinity. This avoids the platform isnan/isinf macros entirely, so it builds on older compilers (e.g. GCC 2.95) that lack __builtin_isnan/isinf and on other compilers that define __GNUC__. Also remove the now-unused ANSI C isnan/isinf fallback macros.
|
Thanks very much @coveyjorjet , for the PR , do you have any idea why it failed with GNU 15.2.0 and worked with GNU 15.3.0 ? or maybe i have something in my local setup that overlap like includes from other compilers (i MSVC and clang installed) ? thanks anyway |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #963
Problem
On MinGW-w64,
isnan/isinfinmath.hare macros that dispatch tofloat-typed helpers (__isnanf,__fpclassifyf, ...) via__builtin_choose_expr. Passing adoublethen triggers:when building with
-Wconversion/-Wfloat-conversion+-Werror(as cJSON's own CMake custom flags do).Fix
Replace the
isnan(d) || isinf(d)call inprint_numberwith a pure C89 IEEE-754 check that only operates ondouble:d != dis true exactly for NaNd > DBL_MAX/d < -DBL_MAXare true exactly for+/-Inf(DBL_MAXis the largest finite double)This avoids the platform
isnan/isinfmacros entirely, so no double-to-float conversion warning is generated. It is also fully ANSI C (C89), so it works on old compilers such as GCC 2.95 that do not provide__builtin_isnan/__builtin_isinf, and on non-GCC compilers that define__GNUC__.The now-unused ANSI C fallback
isnan/isinfmacros were also removed (they would otherwise trigger-Wunused-macroson platforms where they get defined).Verification
-std=c89 -pedantic -Wall -Wextra -Werror -Wconversion -Wfloat-conversion -Wunused-macros ...make testpassesnull; normal numbers unchanged