-
Notifications
You must be signed in to change notification settings - Fork 5k
Add Decimal32, Decimal64, Decimal128 #100729
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
Open
RaymondHuy
wants to merge
54
commits into
dotnet:main
Choose a base branch
from
RaymondHuy:issue-81376
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
ac5e447
add constructor info
RaymondHuy 1af3337
Add Decimal32
RaymondHuy cee05c8
add test cases
RaymondHuy da72dcd
Add Decimal128
RaymondHuy 6f3827c
add tests
RaymondHuy 7e9344b
Merge commit '83b0d939bedadf7d782b0b26307c2d8c1d5b76f4' into issue-81376
RaymondHuy f882b96
Fix digits pointer
RaymondHuy 762f56d
Implement ToString() method.
RaymondHuy 66a1127
resolve comments
RaymondHuy 83937d2
resolve comments
RaymondHuy 19755ba
Refactor shift operators to mask
RaymondHuy ede6ca3
Extract common mask to property.
RaymondHuy b4e5d34
add more tests
RaymondHuy 504f042
add comments
RaymondHuy 31ffd5c
Add overflow message.
RaymondHuy 6212873
Add overflow message
RaymondHuy cb1d8b1
split uint128 to ulong.
RaymondHuy 0a4620e
Change private to internal
RaymondHuy 8f3d4ff
validate overflow decimal case.
RaymondHuy db834cb
add more tests
RaymondHuy 2ed126b
add more tests
RaymondHuy d08b7b5
add more tests
RaymondHuy bcfdca6
Merge branch 'master' into issue-81376
RaymondHuy 472a2fe
Merge branch 'master' into issue-81376
RaymondHuy 49f6676
Correct naming
RaymondHuy f82d9a6
fix naming convention
RaymondHuy 567906c
Merge branch 'main' into issue-81376
tannergooding 70cc09d
Merge branch 'main' into issue-81376
RaymondHuy 715677f
Merge branch 'main' into issue-81376
RaymondHuy a66d209
Merge branch 'main' into issue-81376
RaymondHuy 2405a15
Merge branch 'main' into issue-81376
RaymondHuy 926db20
Merge branch 'main' into issue-81376
RaymondHuy d41c56e
Merge branch 'main' into issue-81376
RaymondHuy ac8f7a6
resolve simple comments
RaymondHuy 9d0fa8e
combine interface
RaymondHuy 4478f54
add XML documentation
RaymondHuy 7b1db43
add XML documentation
RaymondHuy 79bea65
resolve comments
RaymondHuy e9a5cf7
Revert "resolve comments"
RaymondHuy 0a57a1a
resolve comments
RaymondHuy ab7c5fb
resolve comments.
RaymondHuy 6a1c2c3
remove unused fields.
RaymondHuy e584a92
use ArrayPool
RaymondHuy 84ef494
add comments
RaymondHuy 61eaba8
remove constructor
RaymondHuy 2a1fc70
remove constructor
RaymondHuy afc15e4
add rounding method
RaymondHuy 002d9dd
Merge branch 'main' into issue-81376
RaymondHuy 0d598a2
add digit count condition check
RaymondHuy 313c90d
fix wrong rounding
RaymondHuy 7b6a3c0
correct last significand digit.
RaymondHuy d93ac2b
add comments
RaymondHuy c44003e
add more tests
RaymondHuy 9533b39
remove unused test cases
RaymondHuy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment explaining why these numbers are correct would be beneficial.
There's many resources out there that break down the algorithm for how you get to
767
digits for the longest double (or11563
forbinary128
), as it is:But the algorithm for
decimal
isn't as well known (but should overall be similar).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @tannergooding , I have tried your formula but I can't get the
767
result.MaxUnbiasedExponent = 1023, SignificandBits = 52
result is
1023 + (−309) + 1= 715
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I did it from memory initially. It should be
(MaxUnbiasedExponent + TrailingSignificandBits - 1)
So for
double
it is1074 + ⌊log10((2^53 – 1) / 2^1074)⌋ + 1
. This is because the largest subnormal expands to a value that is 1074 digits in length (which is why in many comments and other places you'll see 1074 and 1075 being used)