Not a Number

From SwiftAPI

(Redirected from JavaScript NaN)
Jump to: navigation, search

Contents

C

C99

double x = 0.0 / 0.0;
int y = isnan(x);
// y == 1

Java

double x = 0.0 / 0.0;
boolean y = Double.isNaN(x);
// y == true

JavaScript

var x = 0 / 0;
var y = isNaN(y);
// y == true

PHP

$x = INF / INF;
$y = is_nan($x);
// $y == true

Python

Python 2.6+ only

You can't divide by zero in Python, so we divide infinity by infinity instead

import math
inf = float('infinity')
x = inf / inf
y = math.isnan(x)
# y == True

Ruby

x = 0.0 / 0.0
y = x.nan?
# y == true
Personal tools