java.lang.Math.hypot J# equivalent?

I'm a total newbie to J#, I'm a C# and VB.NET programmer. I know a bit about Java, but not at a professional level, and I need to convert a Java program to J#. The part that I'm stuck on is I need to find a J# equivalent method of:

java.lang.Math.hypot

Any ideas Also, I need to have the same exact results, not a result that is "close enough and will suffice."

Thanks:)



Answer this question

java.lang.Math.hypot J# equivalent?

  • QueenAji

    java.lang.Math.hypot(x, y) is identical with System.Math.Sqrt(x * x + y * y).

    CLR handles Infinity and NaN correctly.


  • Rumi

    Hi,

    We are not supporting this hypot function in our libraries.I have a snippet of code to solve your problem

    public static double hypot(double a, double b)

    {

    a = Math.abs(a);

    b = Math.abs(b);

    if (a < b)

    {

    double temp = a;

    a = b;

    b = temp;

    }

    if (a == 0.0)

    return 0.0;

    else

    {

    double ba = b / a;

    return a * Math.sqrt(1.0 + ba * ba);

    }

    }

    I think this will solve your problem.

    regards,

    Thilak


  • Alexander Dragon

    thanks, that worked like a charm:)


  • java.lang.Math.hypot J# equivalent?