Skip to content

Commit

Permalink
Do not pass integers to isnan (#1664)
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz authored Dec 8, 2024
1 parent 9635cff commit 6ae5423
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mlx/backend/common/ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,12 @@ struct Equal {
struct NaNEqual {
template <typename T>
bool operator()(T x, T y) {
return x == y || (std::isnan(x) && std::isnan(y));
if constexpr (std::is_integral_v<T>) {
// isnan always returns false for integers, and MSVC refuses to compile.
return x == y;
} else {
return x == y || (std::isnan(x) && std::isnan(y));
}
}
};

Expand Down

0 comments on commit 6ae5423

Please sign in to comment.