Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wechat_code): Modify isnan for compatibility with -ffast_math. #3490

Open
wants to merge 2 commits into
base: 4.x
Choose a base branch
from

Conversation

Konano
Copy link
Contributor

@Konano Konano commented May 10, 2023

fix #3150
Merge with opencv/opencv#23881

Reference: https://stackoverflow.com/questions/7263404/mingw32-stdisnan-with-ffast-math

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

union { float v; uint32_t x; } u = { v };
return (u.x & 0x7fffffffu) > 0x7f800000u;
}
inline bool isnan(double v) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asmorkalov
Copy link
Contributor

@Konano Friendly reminder.

Comment on lines 57 to 64
inline bool isnan(float v) {
union { float v; uint32_t x; } u = { v };
return (u.x & 0x7fffffffu) > 0x7f800000u;
}
inline bool isnan(double v) {
union { double v; uint64_t x; } u = { v };
return (u.x & ~0x8000000000000000uLL) > 0x7ff0000000000000uLL;
}
Copy link
Contributor Author

@Konano Konano Jun 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
inline bool isnan(float v) {
union { float v; uint32_t x; } u = { v };
return (u.x & 0x7fffffffu) > 0x7f800000u;
}
inline bool isnan(double v) {
union { double v; uint64_t x; } u = { v };
return (u.x & ~0x8000000000000000uLL) > 0x7ff0000000000000uLL;
}
inline bool isnan(float v) { return cvIsNaN(v); }
inline bool isnan(double v) { return cvIsNaN(v); }

I called cvIsNaN() directly but it doesn't seem to work, it still crashed in the local test.

The new line #include "opencv2/core.hpp" is added in the import section.

Copy link
Contributor Author

@Konano Konano Jun 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compile command:

cmake -G Ninja \
  -D CMAKE_BUILD_TYPE=DEBUG \
  -D CMAKE_INSTALL_PREFIX=../release \
  -D OPENCV_GENERATE_PKGCONFIG=YES \
  -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.7.0/modules \
  -D BUILD_opencv_xfeatures2d=OFF \
  -D BUILD_opencv_freetype=ON \
  -D ENABLE_FAST_MATH=ON ..
ninja -j 24
ninja install
g++ test.cpp -o test -Wall -g `pkg-config --cflags opencv4 --libs opencv4`

Any wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

We chat QR Scan crashes with certain images.
3 participants