From a8fb25f11cf23b2e50a5e2610fce6d417151efc7 Mon Sep 17 00:00:00 2001
From: Jean-Marc Valin <jmvalin@jmvalin.ca>
Date: Wed, 20 Mar 2019 13:36:42 -0400
Subject: [PATCH] Remove NaN checks

---
 dnn/arch.h | 16 ----------------
 dnn/vec.h  | 11 +----------
 2 files changed, 1 insertion(+), 26 deletions(-)

diff --git a/dnn/arch.h b/dnn/arch.h
index 52de62334..0f29b49f9 100644
--- a/dnn/arch.h
+++ b/dnn/arch.h
@@ -157,22 +157,6 @@ typedef float celt_sig;
 typedef float celt_norm;
 typedef float celt_ener;
 
-#ifdef FLOAT_APPROX
-/* This code should reliably detect NaN/inf even when -ffast-math is used.
-   Assumes IEEE 754 format. */
-static OPUS_INLINE int celt_isnan(float x)
-{
-   union {float f; opus_uint32 i;} in;
-   in.f = x;
-   return ((in.i>>23)&0xFF)==0xFF && (in.i&0x007FFFFF)!=0;
-}
-#else
-#ifdef __FAST_MATH__
-#error Cannot build libopus with -ffast-math unless FLOAT_APPROX is defined. This could result in crashes on extreme (e.g. NaN) input
-#endif
-#define celt_isnan(x) ((x)!=(x))
-#endif
-
 #define Q15ONE 1.0f
 
 #define NORM_SCALING 1.f
diff --git a/dnn/vec.h b/dnn/vec.h
index 3853d844a..0b9c289f4 100644
--- a/dnn/vec.h
+++ b/dnn/vec.h
@@ -52,22 +52,13 @@ static float tansig_approx(float x)
     int i;
     float y, dy;
     float sign=1;
-    /* Tests are reversed to catch NaNs */
-    if (!(x<8))
-        return 1;
-    if (!(x>-8))
-        return -1;
-#ifndef FIXED_POINT
-    /* Another check in case of -ffast-math */
-    if (celt_isnan(x))
-       return 0;
-#endif
     if (x<0)
     {
        x=-x;
        sign=-1;
     }
     i = (int)floor(.5f+25*x);
+    i = IMAX(0, IMIN(200, i));
     x -= .04f*i;
     y = tansig_table[i];
     dy = 1-y*y;
-- 
GitLab