Skip to content

Commit 99bab18

Browse files
authored
Address negative zero test issues (#45)
1 parent d10ec64 commit 99bab18

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

mkl_umath/src/mkl_umath_loops.c.src

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,11 @@ pairwise_sum_@TYPE@(char *a, npy_intp n, npy_intp stride)
11611161
{
11621162
if (n < 8) {
11631163
npy_intp i;
1164-
@type@ res = 0.;
1164+
/*
1165+
* Start with -0 to preserve -0 values. The reason is that summing
1166+
* only -0 should return -0, but `0 + -0 == 0` while `-0 + -0 == -0`.
1167+
*/
1168+
@type@ res = -0.0;
11651169

11661170
for (i = 0; i < n; i++) {
11671171
res += @trf@(*((@dtype@*)(a + i * stride)));
@@ -2263,8 +2267,8 @@ pairwise_sum_@TYPE@(@ftype@ *rr, @ftype@ * ri, char * a, npy_intp n,
22632267
if (n < 8) {
22642268
npy_intp i;
22652269

2266-
*rr = 0.;
2267-
*ri = 0.;
2270+
*rr = -0.0;
2271+
*ri = -0.0;
22682272
for (i = 0; i < n; i += 2) {
22692273
*rr += *((@ftype@ *)(a + i * stride + 0));
22702274
*ri += *((@ftype@ *)(a + i * stride + sizeof(@ftype@)));

0 commit comments

Comments
 (0)