mirror of
https://github.com/opencv/opencv.git
synced 2026-11-16 14:27:47 -06:00
core: fix wasm SIMD float rounding - #30213 Summary - Fix rounding in the WebAssembly SIMD implementation of `v_round(const v_float32x4&)`. - Add regression tests for positive and negative halfway values. Motivation The previous implementation added `0.5` before truncating, which caused incorrect results for some negative values and halfway cases. This change uses `wasm_f32x4_nearest` before converting the result to integers, providing round-to-nearest, ties-to-even behavior while preserving the existing saturating conversion. Testing - git diff --check passed. - WebAssembly SIMD tests have not been run yet because Emscripten is not available in my current environment. Pull Request Readiness Checklist - [x] I agree to contribute to the project under the Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on code under GPL or another license incompatible with OpenCV. - [x] The PR is proposed to the proper branch (`4.x`). - [ ] Reference to the original bug report and related work. - [ ] Accuracy/performance tests and test data in `opencv_extra`, if applicable. - [ ] Documentation and sample code, if applicable. Related work: OpenCV 5.x rounding fix in [[PR #30007](https://github.com/opencv/opencv/pull/30007)](https://github.com/opencv/opencv/pull/30007).