cJSON icon indicating copy to clipboard operation
cJSON copied to clipboard

Treat Integers and floating point numbers as totally separated types. Doing int-double or double-double strict comparisons is wrong

Open cr1st1p opened this issue 2 years ago • 1 comments

Issue at hand: a simple json with 1 string field and 1 integer field ("cJSON_addNumber") - fails to be print_unformatted. I saw https://github.com/DaveGamble/cJSON/issues/585 - and someone had a similar problem on my platform - esp8266 RTOS SDK). And the reason of failure is due to some missing feature on my platform for sprintf'ing floating point numbers.

But... a) what I want to use is NOT a floating point number and I should NOT have to compile in some additional functionality for floating numbers b) the fix for the mentioned bug - https://github.com/DaveGamble/cJSON/pull/630/files is wrong. You should never strictly compare floating point numbers (the integer value is most probably converted first to a floating number https://www.cs.technion.ac.il/users/yechiel/c++-faq/floating-point-arith.html Please check to see if you are having other such strict comparisons in your code.

Please treat integer numbers completely separate from floating ones.

cr1st1p avatar Jul 02 '22 08:07 cr1st1p

Again plugging my own PR: #690 has integers as first-class citizens.

abzmr avatar Jul 22 '22 21:07 abzmr