Thursday, August 25, 2005

Floating-Point Numbers

I have been working with floating-point numbers. Floating-point numbers are not exact in computers, they are numbers that closely represent a decimal number.

See the following URL’s for more information floating-point numbers.
www.lahey.com/float.htm
www.codeproject.com/dotnet/ExtremeFloatingPoint1.asp
www2.hursley.ibm.com/decimal/decifaq1.html

Here are some things that I found quite surprising.

1) In Microsoft Excel, enter the following into a cell.

=(0.5 - 0.4 - 0.1)

The result should be 0, however it is actually -2.77556E-17.

2) I created a C# windows applications and dropped a button onto the form and then added the following code to the button’s click event.

double f = Convert.ToDouble("1000000000.12345678901");
MessageBox.Show(f.ToString("0.0000000000000000"));
f = f - 1000000000;
MessageBox.Show(f.ToString("0.0000000000000000"));

When you run the application you will get the following message boxes:

1) 1000000000.1234600000000000
2) 0.1234568357467650

You would expect that the number displayed in the second message box would be 0.12346 because that is what the fractional part is after the initial assignment of the f variable. But it turns out that after you subtract 1 billion, something happens to cause the numbers at the end to appear.

Wednesday, August 17, 2005

Geek Joke

I read this awhile ago. And, the more I think about it, the funnier it becomes. It is funny because it’s true. Then, if you step back from it, it is just plain funny and clever.

From Coding Horror:

A Software Engineer, a Hardware Engineer and a Departmental Manager were on their way to a meeting in Switzerland. They were driving down a steep mountain road when suddenly the brakes on their car failed. The car careened almost out of control down the road, bouncing off the crash barriers, until it miraculously ground to a halt, scraping along the mountainside. The car's occupants, shaken but unhurt, now had a problem: they were stuck halfway down a mountain in a car with no brakes. What were they to do?
"I know", said the Departmental Manager, "Let's have a meeting, propose a Vision, formulate a Mission Statement, define some Goals, and by a process of Continuous Improvement find a solution to the Critical Problems, and we can be on our way."
"No, no", said the Hardware Engineer, "That will take far too long, and besides, that method has never worked before. I've got my Swiss Army knife with me, and in no time at all I can strip down the car's braking system, isolate the fault, fix it, and we can be on our way."
"Well", said the Software Engineer, "Before we do anything, I think we should push the car back up the road and see if it happens again."

Sunday, August 07, 2005

Mashups

I have been listing to some Mashups from www.MashupTown.com. These are awesome peaces of arts. If you have never listened to a Mashups before check out some of my favorites listed below.

Gotta Make Betty Sweat
Sharp dressed party
Bootystition
Spending one of these nights with Kelly
Stairway to Bootleg Heaven