Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. using System;
  2.  
  3. namespace MyArithmetic
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. Console.WriteLine(0.2 + 0.5 == 0.7); // True
  10. Console.WriteLine(0.1 + 0.2 == 0.3); // False
  11.  
  12. Console.WriteLine();
  13.  
  14. Console.WriteLine(Math.Pow(2, 3)); // 8
  15. Console.WriteLine(Math.Pow(2, 3).GetType()); // System.Double
  16. Console.WriteLine(sizeof(int)); // 4
  17. Console.WriteLine(int.MaxValue); // 2147483647
  18. Console.WriteLine(int.MinValue); // -2147483648
  19. Console.WriteLine((int)Math.Pow(2, 31) - 1); // 2147483647
  20. Console.WriteLine((int)Math.Pow(2, 31)); // -2147483648
  21.  
  22. Console.WriteLine();
  23.  
  24. Console.WriteLine(0b0000_0000_0000_0000_0000_0000_0000_0000); // 0
  25. Console.WriteLine(0b0000_0000_0000_0000_0000_0000_0000_0001); // 1
  26. Console.WriteLine(0b1000_0000_0000_0000_0000_0000_0000_0000); // 2147483648
  27. Console.WriteLine(0b1111_1111_1111_1111_1111_1111_1111_1111); // 4294967295
  28. Console.WriteLine(0b1111_1111_1111_1111_1111_1111_1111_1111.GetType()); // System.UInt32
  29.  
  30. Console.WriteLine();
  31.  
  32. unchecked // needed to disable narrowing type conversion error
  33. {
  34. Console.WriteLine((int)0b0000_0000_0000_0000_0000_0000_0000_0000); // 0
  35. Console.WriteLine((int)0b0000_0000_0000_0000_0000_0000_0000_0001); // 1
  36. Console.WriteLine((int)0b1000_0000_0000_0000_0000_0000_0000_0000); // -2147483648
  37. Console.WriteLine((int)0b1111_1111_1111_1111_1111_1111_1111_1111); // -1
  38. Console.WriteLine(((int)0b1111_1111_1111_1111_1111_1111_1111_1111).GetType()); // System.Int32
  39. }
  40.  
  41. Console.WriteLine();
  42.  
  43. {
  44. int numerator = 10;
  45. int denominator = 3;
  46. int quotient = numerator / denominator;
  47. Console.WriteLine(quotient); // 3
  48. int modulus = numerator % denominator;
  49. Console.WriteLine(modulus); // 1
  50. }
  51.  
  52. Console.WriteLine();
  53.  
  54. {
  55. double numerator = 10;
  56. double denominator = 3;
  57. double quotient = numerator / denominator;
  58. Console.WriteLine(quotient); // 3.3333333333333335
  59. }
  60.  
  61. {
  62. int numerator = 1;
  63. int denominator = 0;
  64. //int quotient = numerator / denominator; // uncomment to see runtime error
  65. //Console.WriteLine(quotient);
  66. }
  67.  
  68. Console.WriteLine();
  69.  
  70. {
  71. double numerator = 1;
  72. double denominator = 0;
  73. double quotient = numerator / denominator;
  74. Console.WriteLine(quotient); // ∞
  75. }
  76.  
  77. Console.WriteLine();
  78.  
  79. {
  80. double numerator = 0;
  81. double denominator = 0;
  82. double quotient = numerator / denominator;
  83. Console.WriteLine(quotient); // NaN
  84. }
  85. }
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement