Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

double.IsNaN - What is the compiler doing here

Tags:

c#

When we do something like double.IsNaN -- what exactly is happening?

If double was a class I would understand it, but double is a struct and it is a value type so how does C# actually call a static method on a value type?

like image 717
Jack Kada Avatar asked Mar 18 '10 09:03

Jack Kada


People also ask

What is double Isnan?

Java Double isNaN() MethodThe isNaN() method of Java Double class returns true: If the value of this Object is Not-a-Number (NaN). If the argument passed is Not-a-Number (NaN). Otherwise, the method returns false.

How do you know if a double is NaN?

To check whether a floating point or double number is NaN (Not a Number) in C++, we can use the isnan() function. The isnan() function is present into the cmath library. This function is introduced in C++ version 11.

What is the value of double NaN?

In C#, the Double. NaN field represents a value that is not a number. It is constant.

What is NaN in double C#?

A method or operator returns NaN when the result of an operation is undefined. For example, the result of dividing zero by zero is NaN, as the following example shows. (But note that dividing a non-zero number by zero returns either PositiveInfinity or NegativeInfinity, depending on the sign of the divisor.) C# Copy.


1 Answers

Structs can have methods.

...

Just incase an example is required:

struct Foo {
    public void Hey ()
    {
        Console.WriteLine("hey");
    }

    public static void DoSomething ()
    {
        Console.Read();
    }
}
like image 128
Noon Silk Avatar answered Sep 28 '22 02:09

Noon Silk