Skip to content

Commit ffa8135

Browse files
committed
BUG: fix absolute() returning -NaN for +NaN on scalar path
1 parent 118b179 commit ffa8135

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
* Pinned Cython in the Coverity Scan workflow so generated code stays stable between scans, and added `coverity/README.md` documenting the known Cython-boilerplate false positives and the scan review checklist [gh-266](https://github.com/IntelPython/mkl_umath/pull/266)
1515

1616
### Fixed
17+
* Fixed `absolute` (float32/float64) returning `-NaN` for `+NaN` input on the scalar fallback path (same issue as numpy/numpy@dc478c58b9, gh-31433)
1718
* Fixed an over-decref of the borrowed module dictionary reference on the module initialization error path [gh-264](https://github.com/IntelPython/mkl_umath/pull/264)
1819
* Fixed a leak of the module object when the NumPy C-API import fails during module initialization [gh-263](https://github.com/IntelPython/mkl_umath/pull/263)
1920

‎mkl_umath/src/mkl_umath_loops.c.src‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,10 @@ mkl_umath_@TYPE@_absolute(char **args, const npy_intp *dimensions, const npy_int
917917
else {
918918
UNARY_LOOP {
919919
const @type@ in1 = *(@type@ *)ip1;
920-
const @type@ tmp = in1 > 0 ? in1 : -in1;
920+
/* in1 > 0 ? in1 : -in1 flips sign of +NaN (NaN > 0 is false);
921+
fabs clears the sign bit unconditionally instead.
922+
numpy/numpy@dc478c58b9 (gh-31433) fixed the same bug. */
923+
const @type@ tmp = fabs@c@(in1);
921924
/* add 0 to clear -0.0 */
922925
*((@type@ *)op1) = tmp + 0;
923926
}

0 commit comments

Comments
 (0)