Okay I found the answer it's a result of using optimization flags -Oz
--ffast-math. If you remove one of it - works correctly. Also behavior is
exactly same in clang++, so I think there is no error from emscripten.
My last test case:
#include <cstdio>
#include <cmath>
#include <limits>
int main(int argc, char **argv) {
float val = std::numeric_limits<float>::quiet_NaN();
printf("val '%.2f', isnan:%s\n", val,
std::isnan(val) ? "yes" : "no");
return 0;
}
ср, 2 мар. 2022 г. в 08:46, Александр Гурьянов <[email protected]>:
> I tried to do this but in empty project it works correctly. I converted
> the float to int32_t like this:
>
> int32_t* val = (int32_t) &res;
> printf("%d\n", *val);
>
> and the number was 2143289344, I created testcase:
>
> #include <cmath>
> #include <cstdio>
>
> int main(int argc, char** argv) {
> int32_t nan = 2143289344;
> float* val = (float *) &nan;
>
> printf("val '%.2f', isnan:%s, isinf:%s\n", *val,
> std::isnan(*val) ? "yes" : "no",
> std::isinf(*val) ? "yes" : "no");
>
> return 0;
> }
>
> but it works correctly:
>
> val 'nan', isnan: yes, isinf: no
>
> Moreover in native build of project there is no NAN in problem place, it
> appears only in emscripten build. So, probably error happens somewhere
> else... Trying to understand.
>
> ср, 2 мар. 2022 г. в 00:18, 'Sam Clegg' via emscripten-discuss <
> [email protected]>:
>
>> Perhaps if you print the actual bitpattern at the point of failure you
>> can use that to create a repro case? Without a repro case I think this
>> will be hard to make progress on. Once you have a repro please open an bug
>> report on github.
>>
>> chers,
>> sam
>>
>>
>> On Tue, Mar 1, 2022 at 8:38 AM Александр Гурьянов <[email protected]>
>> wrote:
>>
>>> Hi, I faced problem that std::isnan return false for NAN. I added this
>>> debug printf to my project:
>>>
>>> printf("res %.2f %s %s\n", res,
>>> std::isnan(res) ? "isnan" : "notnan",
>>> std::isinf(res) ? "isinf" : "notinf");
>>>
>>> and when res is NAN, output is following:
>>>
>>> res nan notnan notinf
>>>
>>> I tried to make a simple test case, but in test case it works fine. So,
>>> I think this is a sort of UB, but I run project with valgrind - no errors.
>>> I tried -s ASSERTIONS=1 -s SAFE_HEAP=2, also no errors.
>>>
>>> Any suggestions what it can be?
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "emscripten-discuss" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/emscripten-discuss/CAKOm%3DVHMsym8-XQXp7fb5xz7kaG_fV-M19aj-kUzbdAEbxG7Yg%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/emscripten-discuss/CAKOm%3DVHMsym8-XQXp7fb5xz7kaG_fV-M19aj-kUzbdAEbxG7Yg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "emscripten-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/emscripten-discuss/CAL_va2_hYHdYk7oercuCm4jHmhfo0tiZqoUM2O%3DTiONbpGsqZg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/emscripten-discuss/CAL_va2_hYHdYk7oercuCm4jHmhfo0tiZqoUM2O%3DTiONbpGsqZg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
You received this message because you are subscribed to the Google Groups
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/emscripten-discuss/CAKOm%3DVGtzeNfAFWq%2BqOvH%2BTszifn2n0tP3xQ%3DTZUEZwe2BaqNw%40mail.gmail.com.