Open Zastai opened 2 years ago
ILSpy recognizes MathF
as can be seen here:
However, it only uses MathF
if it can be resolved. We would have to take a look at the assembly and see which version of mscorlib is resolved in your case.
Math.Tau
seems to be a relatively new addition to .NET: https://github.com/dotnet/runtime/issues/24678 which was completed about half a year after we implemented the "constant unfolding" feature in ILSpy. You are the first person making me aware that it even exists... :-)
However, as the "constant unfolding" feature is somewhat brittle and buggy (see #2445 and #2615 for example), I doubt that we will add even more features to it.
It's reproducible for me with dotnet new console
and then changing Program.cs to have Console.WriteLine("Hello, World! - {0} {1} {2}", MathF.E, MathF.PI, MathF.Tau);
using the current .NET 6 SDK.
If I drop the reference to Tau
and change the project to have <TargetFrameworks>netstandard2.1;netcoreapp2.1;netcoreapp3.1;net6.0</TargetFrameworks>
and <LangVersion>10</LangVersion>
, then I can see that the decompilation only produces MathF
references for .NET Standard 2.1, not for any of the .NET Core flavors.
Looking at the references, there's [netstandard]MethF
for .NET Standard, [System.Runtime.Extensions]MathF
for the Core and [System.Runtime]MathF
for .NET 5+.
As part of some testing I had a method call taking 3 floats called with the 3 constants from
MathF
:PI
,E
andTau
.ILSpy's C# view showed that call as taking
((float) Math.PI, (float)Math.E, (float)Math.PI * 2.0f)
. So not only does it seem to be unaware of theTau
constant (which also exists inMath
), it also does not seem to be aware of thefloat
version ofMath
.