Floating Point Special Values With Example C# with Example



Floating Point Special Values With Example C# with Example

 using System;

namespace CSharpFundamentals
{
    class FloatingPointSpecialValuesWithExample
    {
        private static void Main(string[] args)
        {
			Console.WriteLine ("PositiveInfinity and NegativeInfinity");
			Console.WriteLine ("1.0/0.0 : {0}", 1.0/0.0);
			Console.WriteLine ("-1.0/-0.0 : {0}", -1.0/-0.0);
			Console.WriteLine ("-1.0/0.0 : {0}", -1.0/0.0);
			Console.WriteLine ("1.0/-0.0 : {0}\n", 1.0/-0.0);

			Console.WriteLine ("NaN Examples");
			Console.WriteLine ("0.0/0.0 : {0}", 0.0/0.0);
			Console.WriteLine ("(1.0/0.0)-(1.0/0.0) : {0}\n", (1.0/0.0)-(1.0/0.0));
			
			Console.WriteLine ("NaN Comparisons");
			Console.WriteLine ("0.0/0.0 == double.NaN : {0}", 0.0/0.0 == double.NaN);
			Console.WriteLine ("double.IsNaN(0.0/0.0) : {0}", double.IsNaN(0.0/0.0));
			Console.WriteLine ("object.Equals(0.0/0.0 == double.NaN) : {0}", object.Equals(0.0/0.0, double.NaN));
        }
    }
}
 

0 Comment's

Comment Form

Submit Comment