121

"Not a number" is a number :/

Comments
  • 5
    JS 🤦‍♂️
  • 6
    @karma "Jabba the Script" ¯\_(ツ)_/¯
  • 12
    I agree on JS being one of the most counter-intuitive programming languages but this one actually makes sense. If you expect your method to return a value type of number then youre screwed if you get something else. That's why they made NaN of type number so it can be returned by functions that are supposed to return numbers. The caller then just has to check if the value is NaN.
  • 0
    @exelix I know.
    Also, there was a set of puzzles, where I had solved things like these X!=X and
    A ==B, B==C, A!=C.
  • 0
    The society we live in...
  • 4
    To check if something is an apple, you need an apple type thing
  • 0
    It's probably equal to 0
  • 0
    @venky too bad simple stuff like that passes over the head of so-called "developers"
  • 0
  • 0
    isNaN(parseFloat(‘😹🦞🦆’)) === true this is always true!
  • 1
    Came here to say the same thing as @exelix did.

    Quote: "For example, a bit-wise IEEE floating-point standard single precision (32-bit) NaN would be: s111 1111 1xxx xxxx xxxx xxxx xxxx xxxx where s is the sign (most often ignored in applications) and the x sequence represents a non-zero number (the value zero encodes infinities). The first bit from x is used to determine the type of NaN: "quiet NaN" or "signaling NaN". The remaining bits encode a payload (most often ignored in applications)"

    There are some special values in floating point numbers as defined by IEEE-754 there are for example two numers for 0, one when aproaching from + infinite and one for aproaching from - infinite (set by the sign bit) in oposition to the normal two complement integers. There's also a special number for division by zero and for stuff like NaN (ex. Division by +/- infinite and such stuff). So yes technically they are numbers. Just instead of encoding numbers they are agreed upon to encode special/edge cases.
  • 0
    Nani? My brain just crashed seeing this..
Add Comment