mathnet / mathnet-numerics

Math.NET Numerics
http://numerics.mathdotnet.com
MIT License
3.44k stars 891 forks source link

Bug in SpecialFunctions.Hypotenuse #1071

Open lellid opened 3 months ago

lellid commented 3 months ago

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 commented 3 months ago

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