How do I detect if something is equal to NaN?

For custom blocks. Make sure that it doesn't think it's equal to 0.

I think you're in the wrong category to be issuing demands like this.

But still, how can you detect if something's equal to NaN?

I didn't take this as asking for a Snap! feature, just for help in testing for NaN (presumably because his attempt failed with respect to zeros?).

Maybe this would help? :

It's for a custom block I'm making with a text input.

On the basis of

untitled script pic (9)
I've come up with this

untitled script pic (7)
untitled script pic (8)

That didn't work.

Can you post an example of what didn't work?

I can't.

Not even a screenshot?

Okay, fine. Here.

Try this variation instead then

untitled script pic (11)

I need a text input for the custom block.

Can you explain a bit more please?

Can you show your code for your custom block?

script variables ((x) :: grey) :: grey
set [x v] to (... :: grey)
report <not <(x) = (x)>> :: control cap

That doesn't seem to work for me - have you actually got it to detect the difference between NaN and a valid result?

That shouldn't happen... NaN shouldn't be equal to NaN. Snap! is implemented in JavaScript, which uses IEEE standard floats.

I'm not quite understanding what your code is supposed to do.

The OP just wants to be able to detect when something returns NaN

NaN is supposed to never equal any value, including itself or other NaN values. In languages like Java, JavaScript, and other languages that support IEEE standard floating point arithmetic, one way to detect NaN is to assign it to a variable and the variable wouldn't be equal to itself if it is NaN. Try this:
[scratchblocks]<((0) / (0)) = ((0) / (0))>[/scratchblocks] 0/0 is NaN.
Maybe the = block short-circuits to true if the same variable is put on both sides.

Sorry - I thought you had a simple solution to the OPs problem but I see your having a CS discussion :slight_smile: