Hi Sniffman,

You can get rid of the square root **and** divide. How? Calculate 1/sqrt
directly and turn the divides into multiplies.

Google a bit about inverse square root and reciprocal square root. There are hundrets of pages about that stuff out there. For floating point, fixed point, approximations and exact results. The CPU you’re working on might even have a dedicated instruction for that job.

I need to normalize vectors as well, but I’m using square roots and divides because it turned out that the approximation method and using reciprocals lost to much precision for my needs. That costs quite some cycles, but you’ll always get what you pay for.

It depends on what you’re doing, a quick approximation using a small table-lookup and a newton-raphson step for 15 bit precision might be sufficient for your needs. I need full 64 bits of precision, so even float or double wouldn’t do the job for me.

What exactly are you doing, what’s your target hardware and the number-format you’re working with? If I know what you’re after i might know the best solution for you.

Regards,

Nils

Okay, so I’ve been developing a nice little algorithm and have found out that the determination of a 3d vector’s length is by far the most time-intensive part of it. This process is part of adding two non-unit vectors and normalizing the sum. To get the length of the new vector, I have to calculate this rather large square root of sqrt(x² + y² + z²), which eats up time.

So I was wondering if there is any way to eliminate the use of this immense square root, either by finding out the length without using one, or by normalizing without having to divide by the length. But so far, no luck in finding any solutions.