PDA

View Full Version : Dealing with .#INF and .#IND values


Rorschach
10-27-2009, 05:41 PM
I have a problem where a complex algorythm is occasionally returning #IND (indeterminate) values. I've traced it back to a raytracer function supplying and .#INF (infinite) value which, when fed into other functions returns the #IND value.

As to why the raytracer occasioanally does this (I've seen it with the various ray tracing implementations), I don't know, but I've got a feeling it's buggy.

What I do want to know is whether there is a test for these values. At the moment I convert them to string and do a test =="1.#INF", but that seems clumsy and possibly slow when dealing with thousands of values.

I guess I'm looking for something like isNumber, isFloat, isInt, isFinite, isValidNumber? etc....

Thanks

biddle
10-27-2009, 06:13 PM
I'm not sure what would happen in mxs, because there are many layers between you and the actual CPU, but you can test to see if the number is equal to itself.

A == A should be FALSE if A is a NaN (indeterminate).

ypuech
10-27-2009, 06:15 PM
MAXScript Documentation :
bit.isNAN <float>

Returns true if the float is the reserved float value NaN (Not a Number). A NAN is generated when the result of a floating-point operation cannot be represented as a floating point number. An example of NAN is f = (1.0/0.0).

denisT
10-27-2009, 06:15 PM
bit.isNAN, bit.isFinite

#Struct:bit(
or:<fn>,
shift:<fn>,
intAsHex:<fn>,
int64AsDouble:<fn>,
isNAN:<fn>,
flip:<fn>,
xor:<fn>,
intAsChar:<fn>,
intAsFloat:<fn>,
doubleAsInt64:<fn>,
isFinite:<fn>,
set:<fn>,
and:<fn>,
get:<fn>,
not:<fn>,
charAsInt:<fn>,
hexAsInt:<fn>,
floatAsInt:<fn>,
swapBytes:<fn>)

Rorschach
10-27-2009, 06:18 PM
edit: Thank you all, thats just what I was after.

CGTalk Moderation
10-27-2009, 06:18 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.