ashwin.sudhir Posted February 6, 2012 Share Posted February 6, 2012 How do we check if a float is a NaN, denormal etc. in UnigineScript? A quick search of the docs didn't throw up anything... -a. Link to comment
ulf.schroeter Posted February 6, 2012 Share Posted February 6, 2012 Don't think there are any functions for checking invalid float/double values. Use proper pre-condition checks to avoid such conditions (not sure if Unigine would throw runtime exceptions in case of invalid results) Link to comment
ashwin.sudhir Posted February 7, 2012 Author Share Posted February 7, 2012 IMO any floating point library should have these, it's much easier to put an assert( !isnan( f ) ) than sift through a changing codebase and make sure all cases are handled well. Link to comment
ulf.schroeter Posted February 7, 2012 Share Posted February 7, 2012 I would always prefer safe coding techniques because asserts on NaN / denormal are just indications of a deeper algorithmic problem. But of course this is purely a matter of taste Link to comment
ashwin.sudhir Posted February 7, 2012 Author Share Posted February 7, 2012 No, I completely agree, the point of the assert is that we *realize* that there's a deeper algorithmic problem and fix it. The assert is of course, never the solution :( Link to comment
wickedshell Posted February 7, 2012 Share Posted February 7, 2012 Does UnigineScript set any signaling NaN's or are they all quiet? Link to comment
frustum Posted February 13, 2012 Share Posted February 13, 2012 You can use the following function to detect "wrong" fpu numbers: int isnan(int v) { return (v != v); } This is an example: void test(float f) { printf("%s: %d\n",typeinfo(f),isnan(f)); } test(1.0f); test(1.0); test(vec3_one); test(dvec3_one); test(1.0f / 0.0f); test(0.0f / 0.0f); test(1.0 / 0.0); test(0.0 / 0.0); test(vec3_one / 0.0f); test(vec3_zero / 0.0f); test(dvec3_one / 0.0); test(dvec3_zero / 0.0); The result under win32 is: float: 1: 0 double: 1: 0 vec3: 1 1 1: 0 dvec3: 1 1 1: 0 float: 1.#INF: 1 float: -1.#IND: 1 double: 1.#INF: 1 double: -1.#IND: 1 vec3: 1.#INF 1.#INF 1.#INF: 1 vec3: -1.#IND -1.#IND -1.#IND: 1 dvec3: 1.#INF 1.#INF 1.#INF: 1 dvec3: -1.#IND -1.#IND -1.#IND: 1 Link to comment
Recommended Posts