fix(wechat_code): Modify isnan for compatibility with -ffast_math.#3490
Merged
asmorkalov merged 2 commits intoopencv:4.xfrom Sep 6, 2024
Merged
fix(wechat_code): Modify isnan for compatibility with -ffast_math.#3490asmorkalov merged 2 commits intoopencv:4.xfrom
isnan for compatibility with -ffast_math.#3490asmorkalov merged 2 commits intoopencv:4.xfrom
Conversation
| union { float v; uint32_t x; } u = { v }; | ||
| return (u.x & 0x7fffffffu) > 0x7f800000u; | ||
| } | ||
| inline bool isnan(double v) { |
There was a problem hiding this comment.
Lets reuse OpenCV implementation: https://github.com/opencv/opencv/blob/4.7.0/modules/core/include/opencv2/core/fast_math.hpp#L284
Use cvIsNaN() directly.
Contributor
|
@Konano Friendly reminder. |
Konano
commented
Jun 6, 2023
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; | ||
| } |
Contributor
Author
There was a problem hiding this comment.
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.
Contributor
Author
There was a problem hiding this comment.
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?
Contributor
Author
|
@asmorkalov @opencv-alalek Any new progress? |
This was referenced Sep 9, 2024
Merged
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.
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
Patch to opencv_extra has the same branch name.