I recently came across a problem with floating point numbers. I know there are some inherent inaccuracies, but I was surprised to find a problem with a relatively simple number.

Floats are numbers stored as two parts: a whole number and an exponent. Generally you're dealing with numbers on similar scales, i.e. millimetres or kilometres, so this makes sense.

The term "float" refers to the fact that the decimal point 'floats'. For instance the following are all different exponents with the same whole number:

  • 1.1 is 11 x 10-1
  • 0.15 is 15 x 10-2
  • 1.5 is 15 x 10-1
  • 15000.0 is 15 x 103

Simple enough, but I had a bug with 1.1 - I was getting 1.0999999999989! Odd issue until you figure in that computers think in binary. I didn't expect this to be a problem because both the value and the exponent are whole numbers. What I'd failed to realise is that the floating point was also base-2, not base-10. So the floats above are actually:

  • 1.1 is 154811237190861 x 2-47
  • 0.15 is 168884986026394 x 2-50
  • 1.5 is 3 x 2-1
  • 15000.0 is 1875 x 23

Those horrible big numbers for 0.15 and 1.1 are too big for floats to handle. The issue wasn't really the inaccuracy - I expected the float to only be able to deal with a few significant figures. What was a surprise (and shouldn't have been) was that the numbers it has problems with are not the ones I expect it to. To floats 1.1 is an irrational number.

This normally isn't a problem, for most of the sort of calculations where floating point numbers are used a this inaccuracy is worth the fact that the calculation is quicker.

0

Add a comment

And I'll tell you why...

The allegory constantly used by governments and the media is on of a household, and the recession is like the breadwinners losing their jobs. Obviously anyone sensible would cut back, yeah?

But, countries are nothing like households, and that allegory just doesn't work.

The UK will vote on May 5th on whether to switch to the Alternative Vote system (AV) rather than the current First Past The Post (FPTP).

There is a problem in UK banking that's stalling our recovery and it goes something like this:

Banks have two main components: high street lending & saving, and investment banking. The investment banking side took far too many risks in dodgy sub prime investments and lost all the money.

British Airways have the best paid flight staff in the world.

Recently at TechEd Berlin I attended an optimising Javascript presentation that I described as having "lost focus".

I think the current situation with bankers' bonuses shows a complete failure to understand risk and how markets actually work.

There's a TV show in the UK called Property Ladder.

There's a great deal of fuss at the moment about RBS's investment division's planned bonuses. They've made some money (great!) but want to pay over a billion in bonuses, which is over a quarter of the profit.

When .Net originally launched it came with first rate support for Simple Object Access Protocol (SOAP) and at the time I was seriously impressed.

Sightseeing

By this point we were starting to feel the tech-fatigue.

INT303 Building RESTful Services Using Windows Communication Foundation

Jon Flanders I felt the presenter was one of the best and most engaging speakers at the conference.

DAT302 Top 10 Best Practices for Microsoft SQL Server 2008 Analysis Services

Markus Raatz I liked this session - I used to be quite the expert at OLAP optimisation in Analysis Services 2000, and it was good to see that, while the UI was much easier to use, the basic rules have stayed the same.

DEV317 Agile Patterns: Agile Estimations

Stephen Forte (from Telerik) I quite enjoyed this - it was all honestly and well put. His explanations about the cone of uncertainty were good and overall I felt this was a good presentation.

This week I've been attending Tech Ed Europe 2009 - the big Microsoft tech conference. This year it takes place in Berlin. I'm logging my experiences of the event here, with links to the relevant sessions where I can find them, but some sessions require a Tech Ed login to view.

The FSA announced new regulations today - they're going to be tougher on sub-prime lending. The inference is that it's the sub-prime lending that caused the current crisis.

I think that's only a partial truth.

There's nothing fundamentally wrong with sub-prime lending.

Remember to never split an infinitive. A preposition is something never to end a sentence with. The passive voice should never be used. Avoid run-on sentences they are hard to read. Use the semicolon properly, always use it where it is appropriate; and never where it isn't.

Back in the early 00s Internet Explorer 5 was great. I wrote some web applications (which I was really proud of) that used all sorts of then cutting edge stuff like the Microsoft.XmlHttp ActiveX object to load additional data (a method now called Ajax and used everywhere).

5

This content is originally from December 2003. It is an abridged version of an article I sold to Sql Server Central. I was looking for it recently and it took me ages to find it, so I've reproduced relevant parts here.

Suppose that you have two jobs – both are professional jobs for which you are qualified and you have a free choice of either one:

Job A: 3 miles from where you live Lovely, well appointed and air conditioned office Friendly co-workers that you enjoy working with 35 hour week with flexible hours and

My master's thesis is to look at how to apply agile.

There is an awful lot of corporate selling of agile - lots of management consultants selling their brand as 'best'.

I'm not interested whether XP, Scrum, Crystal Clear, Agile-CMMI, Six Sigma or any other brand/variant is best.

No posts for a while, sorry about that. It turns out that I have to be very careful on what I post here as it counts as prior publication for my MBA (and therefore inadmissible).

However I'm going to try and get some community feedback on my conclusions, so they'll be up here soon.

Back in March I asked Are you overpaying your CEO? It seems rather prescient looking at the news today.

The BBC is reporting that Bank shares fall despite bail-out - which is kinda stating the obvious. The government's taken majority stakes - they're basically angel venture capitalists.

Following on from part I I have a few more idea:

Idea 4: Deming's theorys were developed for manufacturing, but have also been applied to software development as the "Agile method".

Investigate using this high particiapation model in other industries.

2

For me Word 2007 has one really 'killer' feature. I didn't think there have been any significant improvements to it since Office 97 - it just gets more expensive and needs more processing with each new version. Now, in Word 2007, they've finally added something that really makes it worth upgrading.

At the moment I'm trying to choose a suitable topic to study for my final MBA year.

I have of late, but how I know not, become rather addicted to stackoverflow.com:

It's currently only in private beta, open to about 2000 users, but I can see it taking off when it goes fully live.

Recently I needed a form, loaded by reflection, that dealt with a collection of some type. I figured that we need to know the type when we loaded the form, so it would be better to have a generic form (save it having to check the object type through reflection for every action).

The Xbox 360's dashboard was quite impressive when the console launched, mainly because it had one at all. However it's not a particularly well designed interface. It works, but it's slow, clunky and wastes a lot of space. There's been rumours of a redesign for a while now.

Nice little graphic on the current state of the web.

I've recently been reading The Black Swan by Nassim Nicholas Taleb. His theory (massively simplified) is that big unexpected events come along despite any existing inductive conjecture, but we're prone to make those conjectures anyway.

There are an awful lot of leadership and management models out there, most appear to be trademarked by consultants offering training in whatever model it is. The MBA teaches lots of them: Blake's Leadership Grid™, Hersey & Blanchard's SLII, Fiedler’s LPC scale, to name but a few.

2

Rather worryingly I've found myself supporting David Davis recently. I would have put the guy as far away from me politically as it's possible to get, yet he's making a stand for something I believe in.

Google's excellent Gmail has been my e-mail of choice for a while - despite the rename to googlemail in the UK. It has by far the best web interface.

Recently I got an email address to First.Surname@domain, which is odd because my e-mail is actually FirstSurname (no ".").

On a related end-of-Friday note:

http://view.break.com/521743 - Watch more free videos

There has always been a clash between those that make a product, and those that sell it.

Software engineers are pessimistic, negative and cynical. All engineers have to be. I don't mean that they have negative personalities as such - they just need to constantly worry about what might go wrong.

1
Label Cloud
Blog Archive
About Me
About Me
Blogroll
Blogroll
Loading