The Result of an Interesting and Useful Program on Floating Numbers

The program: 

 1 class Program
 2 {
 3     static void Main()
 4     {
 5         const double infinity = double.PositiveInfinity;
 6         const double negInfinity = double.NegativeInfinity;
 7         const double nan = double.NaN;
 8         const double max = double.MaxValue;
 9         const double min = double.MinValue;
10         const double somePositive = 12343243252423.5234;
11         Console.WriteLine("max< infinity = {0}", max < infinity);
12         Console.WriteLine("somePositiv<infinity = {0}", somePositive < infinity);
13         Console.WriteLine("negInfinity<-somePositiv = {0}", negInfinity < -somePositive);
14         Console.WriteLine("negInfinity==-infinity = {0}", negInfinity == -infinity);
15         Console.WriteLine("min==-max = {0}", min == -max);
16         Console.WriteLine("min+max==0 = {0}", min + max == 0);
17         Console.WriteLine("negInfinity+infinity==0 = {0}", negInfinity + infinity == 0);
18         Console.WriteLine("negInfinity+infinity= {0}", negInfinity + infinity);
19         Console.WriteLine("nan+nan= {0}", nan + nan);
20         Console.WriteLine("max< nan = {0}", somePositive < infinity);
21         Console.WriteLine("max = {0}", max);
22         Console.WriteLine("min = {0}", min);
23         Console.WriteLine("infinity = {0}", infinity);
24         Console.WriteLine("negInfinity = {0}", negInfinity);
25         Console.WriteLine("nan<infinity = {0}", nan < infinity);
26     }
27 }


The result:

max< infinity = True
somePositiv<infinity = True
negInfinity<-somePositiv = True
negInfinity==-infinity = True
min==-max = True
min+max==0 = True
negInfinity+infinity==0 = False
negInfinity+infinity= NaN
nan+nan= NaN
max< nan = True
max = 1.79769313486232E+308
min = -1.79769313486232E+308
infinity = Infinity
negInfinity = -Infinity
nan<infinity = False

 

posted @ 2014-03-20 18:14  quanben  阅读(204)  评论(0编辑  收藏  举报