Not a number is considered as a number

Use this template to make NaN bug reports:

Your username: NTh3R

What kind of device are you using?: iPad 6th gen, iPadOS 15.0.1

1 sentence description of the problem (I was doing _________, and then __________ happened): I was coding when i noticed “NaN” (not a number) is considered as a number.

Steps that the Hopscotch team can take to reproduce my problem every time:

  1. Create a set text block
  2. Write NaN in it
  3. Quit the block
  4. Click on it to edit the text again and it considers not a number as a number
    ….

I expected this to happen: not a number is not a number

But instead this happened: not a number is a number

Here’s a sweet screenshot:

NaN

NaNN


@Yuanyuan @Awesome_E

6 Likes
  • It happens to me
  • NaN

0 voters

5 Likes

It might be recognizing it as a “Not a Number” Error Code.

It may also be because it’s used to compensate for imaginary (complex) numbers from equations like √(-1) //returns NaN on HS

6 Likes

Hopscotch’s webplayer uses the programming language JavaScript, which (ironically) considers “NaN”/Not a Number to have the same type as “regular” numbers. This means that it is the same for everyone using the language, but it is still possible that THT could implement some checks to get around this since JavaScript contains functions for checking if a number is NaN. I’m not sure what they currently do, though.

Here’s a demonstration of how JavaScript treats NaN. It’s a bit technical but some may understand:

> number = NaN
NaN
> typeof(number)
'number'
8 Likes

NaN in JavaScript is considered a number because statements like "hello" * 839 still have a to return a number, but JavaScript can’t multiply with strings and still end up with a number. So they return NaN.
But this is hopscotch and JavaScript features shouldn’t be used, tht should probably make a workaround for this lol

4 Likes

Yet they still don’t return the square root of negative one as imaginary

3 Likes

True, but some HS coding can fix that

If the number under the radical is less than 0, then return as

((√(abs(number))) + (i)) // √(-4) would return 2i instead of NaN like it normally does in this case. I made a system like this in my Advanced Function Calculator.