Proposal for Interpolation and Extrapolation Interfaces in System.Numerics #108358
Unanswered
StellarWolfEntertainment
asked this question in
Ideas
Replies: 1 comment 1 reply
-
Either i am misunderstanding the motivation behind your proposal (in which case, apologies!), or what exactly is there regarding your suggestion that can't already be relatively easily solved in a generic manner with generic methods constrained to the existing interfaces in the System.Numerics namespace? Implementing Extrapolate/Interpolate as generic methods would not require a new interface and would avoid code duplication (and possible inconsistencies between duplicated code). With respect to your public static TValue Interpolate<TValue>(TValue start, TValue end, TValue factor) where TValue : INumber<TValue>
{
return Extrapolate(start, end, TValue.Clamp(factor, TValue.Zero, TValue.One));
}
public static TValue Extrapolate<TValue>(TValue start, TValue end, TValue factor) where TValue : INumber<TValue>
{
return start + ((end - start) * factor);
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I apologize in advance if this post has landed in the wrong category.
I propose the introduction of generic interfaces for interpolation and extrapolation in the
System.Numerics
namespace. While the immediate use cases may seem limited, these interfaces can provide consistency and flexibility across numeric types.Currently, handling interpolation and extrapolation in numeric operations lacks a standardized approach, which can lead to code duplication and inconsistencies.
The following interfaces could be implemented to streamline interpolation and extrapolation for numeric types:
An example implementation for the Single type (I am going to only post the code relevant to the operations at hand):
By adding these interfaces to the definition of numeric types in C#, we can provide a consistent approach to fairly common operations. Much like how the
ITrigonometricFunctions<T>
interface standardizes handling trigonometric operations with generic types, these interfaces will enhance the flexibility of generic math operations.While the immediate utility might not be apparent, I believe this proposal will open the door for more robust and maintainable code in the future.
Beta Was this translation helpful? Give feedback.
All reactions