Infinit real numners

float and double type defines constant values to represent the positive infinit, negative infinit and NaN(Not a Number).

Special valueDouble constantFloat constant
NaNdouble.NaNfloat.NaN
positive infinitdouble.PositiveInfinityfloat.PositiveInfinity
negetive infinitdouble.NegativeInfinityfloat.NegativeInfinity
-0-0.0-0.0f

Dividing a nonzero number by zero results in an infinite value.

For example:


using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(1.0 / 0.0);  //  Infinity 
        Console.WriteLine(-1.0 / 0.0);  // -Infinity 
        Console.WriteLine(1.0 / -0.0);  // -Infinity 
        Console.WriteLine(-1.0 / -0.0);  //  Infinity
    }
}

The output:


Infinity
-Infinity
-Infinity
Infinity

Dividing zero by zero, or subtracting infinity from infinity, results in a NaN.

For example:


using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine ( 0.0 /  0.0);  //  NaN 
        Console.WriteLine ((1.0 /  0.0) - (1.0 / 0.0));  //  NaN
    }
}

The output:


NaN
NaN
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.