using System.Collections.Generic;
using System.Linq;

namespace DoubleExperiment {
  class Program {
    static void Main(string[] args) {
      double nan = double.NaN;
      double infp = double.PositiveInfinity;
      double infn = double.NegativeInfinity;

      double d = 1;

      System.Console.WriteLine("Basic operations with NaN 1; (+,-,*,/) NaN");
      System.Console.WriteLine(d + nan);
      System.Console.WriteLine(d - nan);
      System.Console.WriteLine(d * nan);
      System.Console.WriteLine(d / nan);
      System.Console.WriteLine("Every number NaN touches becomes NaN itself");
      System.Console.WriteLine();

      System.Console.WriteLine("Basic operations with Nan and Inf; Inf (+,-,*,/) NaN");
      System.Console.WriteLine(infp + nan);
      System.Console.WriteLine(infp - nan);
      System.Console.WriteLine(infp * nan);
      System.Console.WriteLine(infp / nan);
      System.Console.WriteLine();

      System.Console.WriteLine("And what if we reverse the order?");
      System.Console.WriteLine(nan + d);
      System.Console.WriteLine(nan - d);
      System.Console.WriteLine(nan * d);
      System.Console.WriteLine(nan / d);
      System.Console.WriteLine(nan + infp);
      System.Console.WriteLine(nan - infp);
      System.Console.WriteLine(nan * infp);
      System.Console.WriteLine(nan / infp);
      System.Console.WriteLine("Still, every number (even Inf) NaN touches beomes NaN itself");
      System.Console.WriteLine();

      System.Console.WriteLine("Basic operations with Inf+; 1 (+,-,*,/) Inf+");
      System.Console.WriteLine(d + infp);
      System.Console.WriteLine(d - infp);
      System.Console.WriteLine(d * infp);
      System.Console.WriteLine(d / infp);
      System.Console.WriteLine("8 means Infinity, the Console may not print it correctly");
      System.Console.WriteLine();

      System.Console.WriteLine("Basic operations with Inf-; 1 (+,-,*,/) Inf-");
      System.Console.WriteLine(d + infn);
      System.Console.WriteLine(d - infn);
      System.Console.WriteLine(d * infn);
      System.Console.WriteLine(d / infn);
      System.Console.WriteLine("8 means Infinity, the Console may not print it correctly");
      System.Console.WriteLine();

      System.Console.WriteLine("What about ordering?");
      List<double> l = new List<double>();
      l.Add(1);
      l.Add(0);
      l.Add(-1);
      l.Add(double.NaN);
      l.Add(double.NegativeInfinity);
      l.Add(double.PositiveInfinity);
      l.Sort();
      System.Console.WriteLine(string.Join(" ", l));
      System.Console.WriteLine();

      System.Console.WriteLine("And min/max?");
      System.Console.WriteLine("Min " + l.Min());
      System.Console.WriteLine("Max " + l.Max());
    }
  }
}
