Floating Point Arithmetic

1/18/2005 6:36:18 AM

Floating Point Arithmetic

Eric Lippert has a serious of recent blog posts on Floating Point Arithmetic, if you were interested in or following any of my prior math quiz posts. 

Also, Eric Gunnerson talks about floating point arithmetic in a December 2003 post, and posts to a canonical discussion of floating point arithmetic in “What Every Computer Scientist Should Know About Floating-Point Arithmetic.”

Some more math trivia: True or false?

  1. Math.Round(2.5) = 3.
  2. Math.Round returns an int.
  3. Both x and y are expressions of type Double and have the same exact bit representation of a Double in memory. Neither are special cases—ie, NaN, negative zero, denormalized numbers, or infinities. Therefore, x = y.
  4. If x is a Double and x = x, then double.Parse(x.ToString()) = x.
  5. Is MSDN documentation correct in stating the following about Double.Epsilon?

    “Two apparently equivalent floating point numbers might not compare equal because of differences in their least significant digits. For example, the C# expression, (double)1/3 == (double)0.33333, does not compare equal because the division operation on the left-hand side has maximum precision while the constant on the right-hand side is only precise to the visible digit.

    Instead, determine if the two sides of a comparison are close enough to equal for your purposes by comparing whether the absolute value of the difference between the left and right-hand sides is less than Epsilon.”

Comments

 

Navigation

Categories

About

Net Undocumented is a blog about the internals of .NET including Xamarin implementations. Other topics include managed and web languages (C#, C++, Javascript), computer science theory, software engineering and software entrepreneurship.

Social Media