Notifications
Clear all

[Closed] Dealing with .#INF and .#IND values

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

4 Replies

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).

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).

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>)

edit: Thank you all, thats just what I was after.