mathnet-numerics icon indicating copy to clipboard operation
mathnet-numerics copied to clipboard

Bug in SpecialFunctions.Hypotenuse

Open lellid opened this issue 11 months ago • 1 comments

Hello, the implementation of Hypotenuse is buggy. The following test fails:

[Fact]
void TestHypotenuse()
{
  Assert.True(double.IsNaN(SpecialFunctions.Hypotenuse(double.NaN, 0)));
}

This has severe consequences, because e.g. the following test also fails:

 [Fact]
 void TestL2Norm()
 {
   var v = Vector<double>.Build.Dense([double.NaN, 0]);
   Assert.True(double.IsNaN(v.L2Norm()));
 }

Best regards, Dirk

lellid avatar Mar 21 '24 22:03 lellid

Please have a look at the implementation of System.Numerics.Complex.Magnitude. If it not affects performance, you can it even call directly in Hypotenuse.

Dirk

lellid avatar Mar 22 '24 11:03 lellid