Skip to content
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

Add Decimal32, Decimal64, Decimal128 #100729

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

RaymondHuy
Copy link
Contributor

Resolve #81376

Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@RaymondHuy RaymondHuy marked this pull request as draft April 6, 2024 17:29
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Apr 6, 2024
static int IDecimalIeee754UnpackInfo<Decimal128, Int128, UInt128>.NumberDigitsPrecision => NumberDigitsPrecision;


private static Int128[] Int128Powers10 =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Int128 is not optimized, this can be optimally stored as a ReadOnlySpan of Int32/Int64 like Number.BigInteger.Pow10BigNumTable

Comment on lines 104 to 107
public override int GetHashCode()
{
return _value.GetHashCode();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+0 and -0 should have the same hash code. The easiest way can be stripping the sign bit.

I also remember that there can be same values with different representations.

else
{
// Equivalant values are compared by their exponent parts,
// and the value with smaller exponent is considered closer to zero.
// This only applies to IEEE 754 decimals. Consider to add support if decimals are added into .NET.
return 0;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@huoyaoyuan Thanks for your review. However this PR targets only the first phase as following: #81376 (comment) so I haven't added NegativeZero and PositiveZero. I will update GetHashCode method in the next phase.

@tannergooding
Copy link
Member

This is on my radar to take a look at; just noting it might be a bit delayed due to other priorities for the .NET 9 release.

CC. @jeffhandley

This was referenced May 29, 2024
@marchewek
Copy link

sorry for being picky - the last two commits have titles that don't really match the contents, it could be improved (for traceability's sake)

@RaymondHuy
Copy link
Contributor Author

Hi @tannergooding, I'm just curious when this PR can be reviewed ? 😄

@huoyaoyuan
Copy link
Member

Maybe after feature complete of .NET 9. As the original API review, this API is out of scope for .NET 9, as well as BFloat16. Now we are close to final stage of .NET 9 and have really no time to include this.

@tannergooding
Copy link
Member

As huoyaoyuan indicated I would expect to get to this in early .NET 10 at this point in time (there's only around 10 more days before the next snap, at which point we start locking down for RC1).

I really appreciate the effort put into this and the drive to try and get it in, it just wasn't part of the "scheduled" work for .NET 9 and so continued to be deprioritized in comparison to the other feature work going on in the numerics space (mostly due to the size/complexity involved here).

I do still intend to drive this in and will do my best to ensure this is included as part of the scheduled work for .NET 10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Numerics community-contribution Indicates that the PR has been added by a community member new-api-needs-documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: Add Decimal32, Decimal64, and Decimal128 from the IEEE 754-2019 standard.
4 participants