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.

I'm not arguing that they shouldn't cut back at all, but I think a healthy government should be running some degree of deficit during a recession.

Here are my assumptions:

1. There will ALWAYS be boom and bust

We can't stop the cycle of boom and bust, it's been going for hundreds of years and will continue for hundreds more. Maybe one day, but no financial theory to date has come close to a way around them.

With that assumption we should plan for them: busts will happen.

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). I'm a supporter of AV, but FPTP has huge support from both the major parties and from Rupert Murdoch, which means that it both doesn't have a chance and must be the right way on principal.

Fact is anything legal that Murdoch's against I'm for on principal.

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. However if the high street lending & saving side of a big bank fails it does huge damage to the economy, so the government steps in to fill the gap.

British Airways have the best paid flight staff in the world. Their pay is sky high (sorry) – cabin crew can earn up to £56k a year! To put it in context that's more than junior and mid-level doctors – I really don’t see how any cabin crew job can be worth more than even the most junior doctor's role.

BA also run one of the biggest teams per flight – they have 14 on each long-haul plane.

The problem is that flights on BA are expensive.

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

I think this one (from Google) is far more the sort of level and detail that I expected:

This presentation is excellent - in fact I think every developer who ever does any Javascript should view it.

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. Every week through the property boom it followed someone buying and renovating a house with a view to selling it for profit. They found some proper idiots on that show.

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. Creating a SOAP client-server connection was amazingly easy - little more than adding a .asmx file and decorating your methods with the [WebMethod] attribute, and then point your client project at it and Visual Studio does the rest.

What Visual Studio actually does in this case is create a large auto-generated code file from the WSDL.

Sightseeing

By this point we were starting to feel the tech-fatigue. We took the opportunity to see a little of Berlin, before heading back to hit the labs and the convention stalls

DEV301r Microsoft Visual Studio Tips and Tricks

Scott Cate Nice session to finish on - most of these I knew already but a couple were new. They're all on Scott's blog.

Finally all the stands that had prize draws held their raffles.
Label Cloud
Blog Archive
About Me
About Me
Blogroll
Blogroll
Loading