-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: Add missing BigMul overload for uint x uint -> ulong #98346
Comments
Tagging subscribers to this area: @dotnet/area-system-numerics Issue DetailsBackground and motivationMany of the integer types available for other operations are missing for Math.BigMul API Proposalnamespace System;
public static class Math
{
public short BigMul(sbytet a, sbyte b);
public ushort BigMul(bytet a, byte b);
public short BigMul(bytet a, short b);
public uint BigMul(ushort a, ushort b);
public ulong BigMul(uint a, uint b);
} API Usage// Fancy the value
var x = uint.MaxValue;
var y = uint.MaxValue - 1;
var z = Math.BigMul(x, y); Alternative DesignsNo response RisksNo response
|
In fact, there's no arithmetic operator defined for small integer types. They need to be upcasted to 32bit. The default operator already behaves as BigMul. |
Ah i see, the main one IMO that is missing is uint x uint -> ulong, suince we already have int x int -> long |
What's wrong with just using |
It's not as clear and not as easy to take advantage of hardware specific optimizations, particularly on 32-bit platforms.
We have this one internally, so if you update the proposal we can discuss exposing it. Notably, we may want to discuss whether or not this should be |
Updated suggestion accordingly @tannergooding |
Should there be some new |
Sounds reasonable. Maybe Best to make separate api suggestion for that? |
Exposing a different interface for big multiplication is difficult and not necessarily extensible. It only works with very precise types ( You could define a general signature that returns upper/lower halves in a tuple instead, but that can have its own problems as well. |
namespace System;
public static partial class Math
{
public static Int128 BigMul(long a, long b);
public static ulong BigMul(uint a, uint b);
public static UInt128 BigMul(ulong a, ulong b);
}
public readonly partial struct Int32
{
public static long BigMul(int left, int right);
}
public readonly partial struct Int64
{
public static Int128 BigMul(long left, long right);
}
public readonly partial struct UInt32
{
public static ulong BigMul(uint left, uint right);
}
public readonly partial struct UInt64
{
public static UInt128 BigMul(ulong left, ulong right);
} |
Background and motivation
Many of the integer types available for other operations are missing for Math.BigMul
API Proposal
API Usage
Alternative Designs
Only adding it to Uint32 class instead of Math. (BigMul doesnt exist on other concrete types yet, but can be taken in other api suggestion if relevant)
Risks
No response
The text was updated successfully, but these errors were encountered: