On 23 December 2010 21:34, Marnen Laibow-Koser <[email protected]> wrote: > Colin Law wrote in post #970376: >> On 23 December 2010 03:41, Marnen Laibow-Koser <[email protected]> >> wrote: >>> 29114.999999999996362021192908287048 >>> >>> It bears repeating: never, ever use Floats for arithmetic. If you can't >>> use fixed-point math, then use BigDecimal. >> >> I have to disagree here. > > I knew someone would. :)
You probably guessed it might be me :) > >> I would rephrase it as _almost_ never use >> Floats The one time when they would be appropriate is if you have a >> large amount of arithmetic to perform. The sort of thing that might >> occur in complex statistical analysis for example or engineering >> calculations of some sort. On most (possibly all) computers floating >> point consumes vastly less processor time to perform than BigDecimal. > > Then use fixed-point math. IEEE floats are 100% inappropriate for any > sort of mathematical calculation. And who cares how fast they are if > they're inaccurate? Inaccurate engineering calculations are worse than > none at all -- do *you* want to drive over that bridge? :) We are getting off topic for Rails apps but I think if you looked into most engineering and scientific software you would find they use floating point arithmetic. Fixed point is not appropriate as intermediate calculations need guaranteed _relative_ error, not absolute error. That is what floats provide. > If you want to use IEEE floats for arithmetic, then the onus is on you > to do the requisite numerical analysis to figure out how much error you > are introducing, and to inform your users of that fact. Yes of course. As you said, the bridge designer needs to know the possible errors in his calculations. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

