Reply to topic  [ 3 posts ] 
FLOPS 
Author Message
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
Just been learning about numbers and floats and stuff...

Specifically learning the inadequacies of floating point operations (i.e. 10.0f * 0.03f <> 0.3f)

Is using floats for arithmetic generally a bad idea or are the inacurracies something that most people aren't affected by?

I can't imagine I'm going to be using anything like this for a while but I wanted to ask whilst I'm on this section of the book.

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Thu Jan 27, 2011 1:42 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 6:58 pm
Posts: 8767
Location: behind the sofa
Reply with quote
You certainly need to be aware of their limitations and use them accordingly. It's particularly important when adding or subtracting numbers with very different indices. Where possible, formulae should be re-arranged so that any subtractions are done either at the very end or when operands are of similar size. Re-arranging a formulae with a couple of brackets can be the difference between them working satisfactorily or not.

_________________
jonbwfc's law: "In any forum thread someone will, no matter what the subject, mention Firefly."

When you're feeling too silly for x404, youRwired.net


Thu Jan 27, 2011 4:21 pm
Profile WWW
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 4876
Location: Newcastle
Reply with quote
Fogmeister wrote:
Is using floats for arithmetic generally a bad idea or are the inacurracies something that most people aren't affected by?


They are fine if it's an operation on a large number and you aren't too fussed about accuracy, we did have 0.3 store in the db as 0.300017 or so though so for precision use a double, decimal or similar

_________________
Twitter
Charlie Brooker:
Macs are glorified Fisher-Price activity centres for adults; computers for scaredy cats too nervous to learn how proper computers work; computers for people who earnestly believe in feng shui.


Thu Jan 27, 2011 10:38 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.