From 63ce5c37c057b788a9a0062b8f1f9633fc272c66 Mon Sep 17 00:00:00 2001 From: Inkrementator <70717315+Inkrementator@users.noreply.github.com> Date: Mon, 17 Mar 2025 21:37:00 +0100 Subject: [PATCH] Optimization: Move NaN-check inside branch where it is guaranteed to happen --- std/math/algebraic.d | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/std/math/algebraic.d b/std/math/algebraic.d index 929e90ea2..a331668a9 100644 --- a/std/math/algebraic.d +++ b/std/math/algebraic.d @@ -322,10 +322,10 @@ if (isFloatingPoint!T) u = fabs(y); if (u == T.infinity) return u; // hypot(inf, nan) == inf if (v == T.infinity) return v; // hypot(nan, inf) == inf + if (u.isNaN || v.isNaN) + return T.nan; } - - if (u.isNaN || v.isNaN) - return T.nan; + assert(!(u.isNaN || v.isNaN), "Comparison to NaN always fails, thus is is always handled in the branch above"); const maxabs = max(u,v); if (v == 0.0)