-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
base: 4.x
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@Konano Friendly reminder. |
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asmorkalov @opencv-alalek Need help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
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.