Chakracore: How to identify NaN?

Created on 5 Oct 2018  路  4Comments  路  Source: chakra-core/ChakraCore

How can I indentify an NaN value with the JSRT APIs?
JsGetValueType returns JsNumber (which seems to be consistent with the expected behavior for "typeof NaN"), and JsNumberToInt returns 0. So, I'm having trouble distinguishing between NaN and a valid number.

Answered Question

Most helpful comment

I think you can use the JsStrictEquals API https://github.com/Microsoft/ChakraCore/wiki/JsStrictEquals

As NaN is the one value in Js which does not equal itself:

const val = NaN;
print(val === val); // prints false

All 4 comments

I guess maybe I just have to call isNan()?

Have you tried JsNumberToDouble()? I believe it should return a standard double NaN value. Alternately you could call Number.isNaN.

I think you can use the JsStrictEquals API https://github.com/Microsoft/ChakraCore/wiki/JsStrictEquals

As NaN is the one value in Js which does not equal itself:

const val = NaN;
print(val === val); // prints false

From JSRT, I think JsStrictEquals is probably the most straightforward, though you should probably comment it since checking for x === x isnt particularly clear :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stefanpenner picture stefanpenner  路  5Comments

basdl picture basdl  路  3Comments

tommyZZM picture tommyZZM  路  5Comments

Funkwai picture Funkwai  路  6Comments

tommyZZM picture tommyZZM  路  4Comments