Fix crash when doing sim.ambientAirTemp(0/0)

This commit is contained in:
jacob1 2021-06-17 23:21:29 -04:00
parent 5eb2495d61
commit b0e29c8c23
No known key found for this signature in database
GPG Key ID: 4E58A32D510E1995

View File

@ -1,6 +1,7 @@
#ifndef UTILS_H #ifndef UTILS_H
#define UTILS_H #define UTILS_H
#include "Config.h" #include "Config.h"
#include <cmath>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <vector> #include <vector>
@ -43,9 +44,12 @@ inline unsigned clamp_flt(float f, float min, float max)
inline float restrict_flt(float f, float min, float max) inline float restrict_flt(float f, float min, float max)
{ {
if (f<min) // Fix crash in certain cases when f is nan
if (!std::isfinite(f))
return min; return min;
if (f>max) if (f < min)
return min;
if (f > max)
return max; return max;
return f; return f;
} }