Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IsFinite() equivalent

Tags:

c++

c#

What is the C# replacement for the following define?

#define IS_FINITE(x) (0x7FF0 != (*((unsigned short*)(&x) + 3) & 0x7FF0))

Maybe double.IsInfinity(x) == false or double.IsNegativeInfinity(x) == false?

Thanks.

like image 540
abenci Avatar asked Apr 05 '12 14:04

abenci


People also ask

What is isFinite?

isFinite is a function property of the global object. You can use this function to determine whether a number is a finite number. The isFinite function examines the number in its argument. If the argument is NaN , positive infinity, or negative infinity, this method returns false ; otherwise, it returns true .

What is isFinite number?

Finite number may refer to: A countable number less than infinity, being the cardinality of a finite set – i.e., some natural number, possibly 0. A real number, such as may result from a measurement (of time, length, area, etc.)

How do you check if a value is a number in JavaScript?

In JavaScript, there are two ways to check if a variable is a number : isNaN() – Stands for “is Not a Number”, if variable is not a number, it return true, else return false. typeof – If variable is a number, it will returns a string named “number”.


1 Answers

!double.IsInfinity(x) && !double.IsNaN(x)

References:
http://pubs.opengroup.org/onlinepubs/009604499/functions/isfinite.html
http://msdn.microsoft.com/en-us/library/system.double.isinfinity.aspx
http://msdn.microsoft.com/en-us/library/system.double.isnan.aspx

like image 87
Danny Varod Avatar answered Sep 19 '22 18:09

Danny Varod