X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Freal.h;h=e72709ba427610199cd37eb468bebe231d9fe481;hp=42bc5c09a049c01cb45317b2795b7650eb725bfd;hb=f3452f32fba45b1f317e4a6a1906d16068ce3bdf;hpb=a54254dcb23c8db9b78d5bd42e1ca54efda4c8e8 diff --git a/src/real.h b/src/real.h index 42bc5c0..e72709b 100644 --- a/src/real.h +++ b/src/real.h @@ -3,6 +3,7 @@ #include "common.h" #include +#include #define REAL_SINGLE 0 @@ -139,6 +140,13 @@ namespace IPDF inline double Log10(double a) {return log(a)/log(10.0);} inline size_t Size(double a) {return sizeof(a);} inline size_t Size(float a) {return sizeof(a);} + + // Don't cause an exception + inline float ClampFloat(double d) + { + float f = (fabs(d) < FLT_MAX) ? ((fabs(d) > FLT_MIN) ? (float)d : FLT_MIN) : FLT_MAX; + return copysign(f, d); + } inline int64_t Int64(double a) {