std::nearbyint returns nan for any argument #35

Closed
opened 2026-01-29 22:24:06 +00:00 by claunia · 1 comment
Owner

Originally created by @dmik on GitHub (Sep 11, 2020).

Originally assigned to: @dmik on GitHub.

std::nearbyint is a modern rounding function in C++.

This following program:

#include <iostream>
#include <cmath>
 
int main()
{
  double d1 = 127.00000;
  std::cout << d1 << ' ' << std::nearbyint(d1) << '\n';
  return 0;
}

outputs 127 nan instead of 127 127 for some reason.

Note that any other double instead of 127 results in nan as well.

Spotted here: https://github.com/bitwiseworks/qtwebengine-chromium-os2/issues/21#issuecomment-691239455.

Originally created by @dmik on GitHub (Sep 11, 2020). Originally assigned to: @dmik on GitHub. [`std::nearbyint`](https://en.cppreference.com/w/cpp/numeric/math/nearbyint) is a modern rounding function in C++. This following program: ```c++ #include <iostream> #include <cmath> int main() { double d1 = 127.00000; std::cout << d1 << ' ' << std::nearbyint(d1) << '\n'; return 0; } ``` outputs `127 nan` instead of `127 127` for some reason. Note that any other double instead of 127 results in `nan` as well. Spotted here: https://github.com/bitwiseworks/qtwebengine-chromium-os2/issues/21#issuecomment-691239455.
Author
Owner

@dmik commented on GitHub (Sep 11, 2020):

Well, C++ just forwards these calls to libc, so it should be fixed there. Created https://github.com/bitwiseworks/libc/issues/87 and will close this one.

I spotted another problem though. An attempt to include fails with multiple errors. Created #31 for it.

@dmik commented on GitHub (Sep 11, 2020): Well, C++ just forwards these calls to libc, so it should be fixed there. Created https://github.com/bitwiseworks/libc/issues/87 and will close this one. I spotted another problem though. An attempt to include <cfenv> fails with multiple errors. Created #31 for it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: bitwiseworks/gcc-os2#35