runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Add reciprocal and SinCos methods to IFloatingPoint

Open lilinus opened this issue 5 years ago • 8 comments

Background and Motivation

Suggestion for the generic math. The mentioned methods are available in Math and MathF classes. I think it would be nice to add these to the IFloatingPoint interface.

Proposed API

namespace System
{
    public interface IFloatingPoint<TSelf>
    {
...
+        (TSelf, TSelf) SinCos(TSelf x);
+        TSelf ReciprocalEstimate(TSelf x);
+        TSelf ReciprocalSqrtEstimate(TSelf x);
...
    }
}

Oops forgot to add api suggestion label...

lilinus avatar Sep 03 '21 08:09 lilinus

Tagging subscribers to this area: @dotnet/area-system-numerics See info in area-owners.md if you want to be subscribed.

Issue Details

Background and Motivation

Suggestion for the generic math. The mentioned methods are available in Math and MathF classes. I think it would be nice to add these to the IFloatingPoint interface.

Proposed API

namespace System
{
    public interface IFloatingPoint<TSelf>
    {
...
+        (TSelf, TSelf) SinCos(TSelf x);
+        TSelf ReciprocalEstimate(TSelf x);
+        TSelf ReciprocalSqrtEstimate(TSelf x);
...
    }
}
Author: lilinus
Assignees: -
Labels:

area-System.Numerics, untriaged

Milestone: -

ghost avatar Sep 03 '21 08:09 ghost

They are more about low-level optimization, when you know the hardware support for some specific type, and looks unsuitable for generic. The interface should contain primitive methods only.

huoyaoyuan avatar Sep 03 '21 09:09 huoyaoyuan

They are more about low-level optimization, when you know the hardware support for some specific type, and looks unsuitable for generic. The interface should contain primitive methods only.

The functions exist as more than just hardware optimizations and they are fully suitable for use in general algorithms, hence why they are on Math/MathF and not some other type.

These were simply missed from the initial preview due to the functions being new in .NET 6.

tannergooding avatar Sep 07 '21 13:09 tannergooding

Video

Looks good as proposed.

namespace System
{
    public interface IFloatingPoint<TSelf>
    {
+        (TSelf Sin, TSelf Cos) SinCos(TSelf x);
+        TSelf ReciprocalEstimate(TSelf x);
+        TSelf ReciprocalSqrtEstimate(TSelf x);
    }
}

bartonjs avatar Sep 21 '21 18:09 bartonjs

@lilinus are you interested in working on this one?

danmoseley avatar Mar 08 '22 19:03 danmoseley

This is one that isn't easy to pick up at the moment since it impacts generic math.

We're working through several parallel changes to get it in box before additional work/changes can happen here.

tannergooding avatar Mar 08 '22 19:03 tannergooding

Sure, I can pick it up if @i3arnon who has a PR doesn't want to. Will keep an eye out for when generic math is potentially ready for this change.

lilinus avatar Mar 15 '22 13:03 lilinus

@lilinus Thanks for the heads up. I indeed want it but AFAICT my existing PR is good enough at this moment. I can update it accordingly when the other generic math changes are done.

i3arnon avatar Mar 15 '22 13:03 i3arnon