diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2022-04-01 14:51:33 -0700 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2022-06-13 09:36:57 -0700 |
commit | 341d9885120123675737ab83e69b9642b28aeb17 (patch) | |
tree | c15ad61552b3fed8341ee8ec63f48e3aeaf29236 | |
parent | 8735980bd44446a789aa00b9e05cfffe4d583dae (diff) | |
download | numpy-341d9885120123675737ab83e69b9642b28aeb17.tar.gz |
BUG: Avoid FPE for float NaN to datetime/timedelta casts
-rw-r--r-- | numpy/core/src/multiarray/arraytypes.c.src | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src index d7d54a2c6..62a96e371 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -1153,12 +1153,17 @@ static void while (n--) { @fromtype@ f = *ip++; - @totype@ t = (@totype@)f; #if @supports_nat@ && @floatingpoint@ - /* Avoid undefined behaviour for NaN -> NaT */ + @totype@ t; + /* Avoid undefined behaviour and warning for NaN -> NaT */ if (npy_isnan(f)) { t = (@totype@)NPY_DATETIME_NAT; } + else { + t = (@totype@)f; + } +#else + @totype@ t = (@totype@)f; #endif *op++ = t; } @@ -1179,12 +1184,17 @@ static void while (n--) { @fromtype@ f = *ip; - @totype@ t = (@totype@)f; #if @supports_nat@ - /* Avoid undefined behaviour for NaN -> NaT */ + @totype@ t; + /* Avoid undefined behaviour and warning for NaN -> NaT */ if (npy_isnan(f)) { t = (@totype@)NPY_DATETIME_NAT; } + else { + t = (@totype@)f; + } +#else + @totype@ t = (@totype@)f; #endif *op++ = t; ip += 2; |