These routines compute Euclidean Norm (distance) accurately without overflow unless the results overflow.
No warranty, express or implied, should be assumed for these code fragments. They are for educational and demonstration purposes, and may contain major errors.
This is a C implementation of Cleve Moler's Euclidean Norm algorithm. This algorithm is documented in the IBM Journal of Research and Development, Vol27, No 6, November 1983.
In effect, it computes sqrt(x*x+y*y), but it doesn't compute x*x or y*y so it will not overflow unless the answer overflows. The algorithm is generally much faster than the sqrt routine on a given machine.
This page is http://www.cc.utah.edu/~nahaj/c/math/enorm.html © Copyright 2001 by John Halleck, All Rights Reserved. This snapshot was last modified on May 17th, 2001