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

- 08-14-2006ammalikdoing floating operations using integer operations
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 - 08-14-2006OnionKnight
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. - 08-14-2006dwks
Why don't you want to use floating point numbers?

- 08-14-2006CornedBee
You could use fixed-point math. But you'll have to write pretty much everything yourself.

- 08-14-2006VirtualAce
Floating point on modern machines is a tad faster than integer ops. No need for fixed point anymore.

- 08-14-2006jafetQuote:

How one can do floating point operations ... ... ... with out using any floating point operations

**unsigned long long**comes to mind. - 08-14-2006FillYourBrainQuote:

Originally Posted by**jafet**

how does a 64 bit integer solve his problem? - 08-14-2006dwks
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. - 08-14-2006quzah
Sometimes you need accuracy over speed. Floating point isn't accurate.

Quzah. - 08-14-2006dwks
Like with money. You wouldn't want ten thousand 99 dollar items to cost $9900.13, now would you?

- 08-15-2006jafet
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.