X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Freal.h;fp=src%2Freal.h;h=e72709ba427610199cd37eb468bebe231d9fe481;hp=42bc5c09a049c01cb45317b2795b7650eb725bfd;hb=c4f8f7c6c7e43fc9fd5358197ca866b4186f636c;hpb=a9883b166454c794e342ccc262ca97e0394af980;ds=sidebyside 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) {