Level: New Member

Joined: Tue. Dec 12, 2017

Posted by cteffects:
Tue. Dec 12, 2017 - 04:02 AM
I'm writing routine that depends on calculating a (potentially large) vector length where the components are stored in an array of 32-bit signed integer format.

I'm essentially trying to calculate

sqrt(x*x + y*y + z*z + ...)

for any vector component that can fit in 32 bits. The problem is that the intermediate value can quickly grow beyond even a 64-bit int.

Is there even a way to mathematically "break up" the calculation into an iterative (and possibly slower) process, while compounding some smaller terms like sqrt(x*x) + sqrt(y*y)? This obviously produces a different result, but the storage required never grows beyond 64 bits for 32 bit operands, and I'd like to transform the above expression into something similar while still producing the correct result.

My goal is robustness without resorting to floats.

## Tags:

Last Edited: Tue. Dec 12, 2017 - 05:08 AM