How one can do floating point operations with using only integer operations e.g. finding r in x^2 + y^2 = r^2 with out using any floating point operations
Thanks
Printable View
How one can do floating point operations with using only integer operations e.g. finding r in x^2 + y^2 = r^2 with out using any floating point operations
Thanks
x*x + y*y? Don't think there's any different approach to sqrt() though.
In situations where you need multiplication you can use fractions instead of floats, e.g (x*355)/113 instead of x*pi or (x*95)/100 instead of x*0.95. This introduces a possible problem with integer overflow though.
Why don't you want to use floating point numbers?
You could use fixed-point math. But you'll have to write pretty much everything yourself.
Floating point on modern machines is a tad faster than integer ops. No need for fixed point anymore.
:rolleyes:Quote:
How one can do floating point operations ... ... ... with out using any floating point operations
unsigned long long comes to mind.
?Quote:
Originally Posted by jafet
how does a 64 bit integer solve his problem?
You use fixed point math, which, as Bubba pointed out, isn't much faster anymore.
An example is storing monetary values in an integer, the cent value in the first two digits, and dollars in the other digits. To store $14.68, you would store 1468. There's a fixed point -- the decimal point is always in the second place.
Sometimes you need accuracy over speed. Floating point isn't accurate.
Quzah.
Like with money. You wouldn't want ten thousand 99 dollar items to cost $9900.13, now would you?
Of course I would! That'd be nearly 99% off the store price! It's always nice to buy in bulk :) Unless you meant, of course, 99 cents per item.