Svetli0o

ComparingFloats

Mar 9th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2.  
  3. class ComparingFloats
  4. {
  5.     static void Main()
  6.     {
  7.         float a = 5.500001f;
  8.         double b = 5.500001;
  9.         float eps = 0.000001f;
  10.         double difference = b - a;
  11.         if (((difference <= eps) || (difference >= eps && difference <= 0.000009)) && (difference >= 0))
  12.         {
  13.             Console.WriteLine(a + " is equal to " + b + " with precision of 0.000001");
  14.         }
  15.         else if (difference > eps)
  16.         {
  17.             Console.WriteLine(b + " is bigger than " + a + " with precision of 0.000001");
  18.         }
  19.         else if (difference < eps)
  20.         {
  21.             Console.WriteLine(a + " is bigger than " + b + " with precision of 0.000001");
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment