diff options
author | William Joye <wjoye@cfa.harvard.edu> | 2017-09-14 15:20:33 (GMT) |
---|---|---|
committer | William Joye <wjoye@cfa.harvard.edu> | 2017-09-14 15:20:33 (GMT) |
commit | 2f5962654cfc46093598257f98c18d2a61816b1f (patch) | |
tree | 6ef84f9a6323b3c91a4d3bc80d66b48a3ca94686 /tksao/util | |
parent | 643cfddc7d1d89dbb580cb1ec7e5235d60dbb3fe (diff) | |
download | blt-2f5962654cfc46093598257f98c18d2a61816b1f.zip blt-2f5962654cfc46093598257f98c18d2a61816b1f.tar.gz blt-2f5962654cfc46093598257f98c18d2a61816b1f.tar.bz2 |
prevent freeze when bad value sent to radToDeg or degToRad
Diffstat (limited to 'tksao/util')
-rw-r--r-- | tksao/util/util.C | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/tksao/util/util.C b/tksao/util/util.C index 800b9da..052aa27 100644 --- a/tksao/util/util.C +++ b/tksao/util/util.C @@ -115,6 +115,9 @@ char* toConstUpper(const char* str) double zeroTWOPI(double aa) { + if (isnan(aa) || isinf(aa) || (aa == -DBL_MAX) || (aa == DBL_MAX)) + return NAN; + double rr = aa; if (rr>0) while (rr>=M_TWOPI) @@ -127,6 +130,9 @@ double zeroTWOPI(double aa) double zero360(double aa) { + if (isnan(aa) || isinf(aa) || (aa == -DBL_MAX) || (aa == DBL_MAX)) + return NAN; + double rr = aa; if (rr>=0) while (rr>360) @@ -139,6 +145,9 @@ double zero360(double aa) double m180To180(double aa) { + if (isnan(aa) || isinf(aa) || (aa == -DBL_MAX) || (aa == DBL_MAX)) + return NAN; + // incoming 0-360 double rr = aa; if (rr>180) @@ -146,15 +155,21 @@ double m180To180(double aa) return rr; } -double degToRad(double dd) +double degToRad(double aa) { - double rr = M_PI*dd/180.; + if (isnan(aa) || isinf(aa) || (aa == -DBL_MAX) || (aa == DBL_MAX)) + return NAN; + + double rr = M_PI*aa/180.; return zeroTWOPI(rr); } -double radToDeg(double rr) +double radToDeg(double aa) { - double dd = 180.*rr/M_PI; + if (isnan(aa) || isinf(aa) || (aa == -DBL_MAX) || (aa == DBL_MAX)) + return NAN; + + double dd = 180.*aa/M_PI; return zero360(dd); } |