The Result of an Interesting and Useful Program on Floating Numbers

6258 ワード

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 = TruesomePositiv