I am working with the new Generic Math System in C# 11, which is cool, but I haven't found a way to use numeric literals or mathematical constants with them.
The following example which calculates the circumference of a circle does not work.
public T Circumference<T>(T radius) where T : INumber<T>
{
return 2 * Math.PI * radius;
}
The int (2) and double (Math.PI) cannot be converted to T. This also doesn't work when using the IFloatingPoint interface instead of INumber.
Is there any way to use constants and literals in conjunction with Math Generics?