About

I am a software developer in Seattle, building a new AI software company.

Ads

May 2012

Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Ads


« Math Quiz II | Main | Pointers in VB »

January 10, 2005

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d8345242f069e200d83422a8ec53ef

Listed below are links to weblogs that reference Numbers in .NET:

» A must read about numbers in .NET from Insert Zippy Title Here
[Read More]

» RE: Numbers in .NET from IImplement
[Read More]

» Dealing With Numbers from Stuart Radcliffe
When there is a possibility of an overflow condition many of the normal math rules break down. [Read More]

Comments

Jeroen Frijters

Here are two more:

If x is an int:

1. -x = x * -1
2. -x = x / -1

Marius

Does anybody have an ideea how to demonstrate (in Excel or .NET) that

(a+b) + c != a + (b+c)

?

Thank you

Wesner Moise

Excel is a little harder, because of Visual Rounding after calculating the result but perform placing the value in a cell. In effect, Excel makes double values behaves as if they were written in base ten.

Jeffrey Sax

Great little quizzes. Regarding the 'new' issues in .NET:

1. This isn't exactly true. The default behavior (according to the IEEE-754 standard) should be that floating-point exceptions are signaled (i.e. a flag is raised in the FPU status register), but execution continues with a default value. For operations like 0/0 and Inf/Inf, this default value is NaN. For underflow it's 0, and for overflow it's +/-Inf.

In C++ and many other languages, you can detect FP exceptions by inspecting the status register, and - if you choose to - trap them as they occur.

The CLI specification states that the default behavior is what we get. Nothing more.

2. This isn't new to .NET.

3. "a double to single conversion always succeeds" is true, but if the value is outside the range of single, then either 0 or Infinity is returned.

Question 8 of the Double quiz is interesting. A NaN value has a biased exponent of 2047 (11 ones) and a non-zero mantissa. NaN's were originally intended to carry more information (a 'payload') in the mantissa bits. The CLI doesn't make this distinction. It treats NaN's as one value regardless of the payload. So even if x and y are NaN's with different payloads, x.Equals(y) will still be true.

In other words, if x.Equals(y) then BitConverter.DoubleToInt64Bits(x) == BitConverter.DoubleToInt64Bits(y) is false.

And finally: the statement "Operations on Double values are always carried out in at least double precision" is also false. See the 'How Do I...' section on http://msdn.microsoft.com/library/en-us/directx9_m/directx/ref/ns/microsoft.directx.direct3d/c/device/m/ctor3.asp

The comments to this entry are closed.