|
using System;
namespace MaNet
{
/// <summary>
/// Minor staic class to hold hypot method
/// </summary>
static class Maths
{
/// <summary>
/// sqrt(a^2 + b^2) without under/overflow.
/// </summary>
/// <param name="a">a</param>
/// <param name="b">a</param>
/// <returns>the length of the radius defined by a and b</returns>
public static double Hypot(double a, double b)
{
double r;
if (Math.Abs(a) > Math.Abs(b))
{
r = b / a;
r = Math.Abs(a) * Math.Sqrt(1 + r * r);
}
else if (b != 0)
{
r = a / b;
r = Math.Abs(b) * Math.Sqrt(1 + r * r);
}
else
{
r = 0.0;
}
return r;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Written software for what seems like forever. I'm currenly infatuated with WPF. Hopefully my affections are returned.