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

Flesh out Decimal API and allow rounding to negative decimal places #33126

Open
charlesroddie opened this issue Mar 3, 2020 · 6 comments
Open
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Numerics backlog-cleanup-candidate An inactive issue that has been marked for automated closure. no-recent-activity
Milestone

Comments

@charlesroddie
Copy link

charlesroddie commented Mar 3, 2020

The Decimal API (taken here to include System.Double API where this includes decimal representations) is rather thin and needs rounding out.

  1. Rounding to negative decimal places:
    Decimal.Round(_,digits:int) and Math.Round(_,digits:int) should allow digits to be negative.
    For example Decimal.Round(123M,-1) should give 120M.

  2. Creating a Decimal from components, and getting the components of a Decimal: Decimal.FromComponents(positive:bool,exponent:int,significand:Decimal) and Decimal.Exponent(d:Decimal) and Decimal.Significand().

  3. Decimal.Pow(d:Decimal, exponent:int)

At the moment multiplying a decimal by 10^n, an extremely simple operation, is very hard.

See https://developer.apple.com/documentation/foundation/decimal for Swift's more complete API.

Related: a normalization method has been suggested here.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Runtime untriaged New issue has not been triaged by the area owner labels Mar 3, 2020
@charlesroddie charlesroddie changed the title Add Decimal operations Flesh out Decimal API and allow rounding to negative decimal places Mar 3, 2020
@Wraith2
Copy link
Contributor

Wraith2 commented Mar 3, 2020

What does it mean to be a canonical decimal?

@svick
Copy link
Contributor

svick commented Mar 3, 2020

decimal doesn't support infinite values, so I think IsFinite and IsInfinite don't make sense.

@charlesroddie
Copy link
Author

@svick @Wraith2 maybe I copied too much from the Swift api. Deleted those parts.

@tannergooding
Copy link
Member

tannergooding commented Mar 4, 2020

The System.Decimal and the Swift decimal types are not the same and are intended for different usages.

System.Decimal is based on the Win32 DECIMAL type: https://docs.microsoft.com/en-us/windows/win32/api/wtypes/ns-wtypes-decimal~r1
While I believe the Swift decimal` type is closer to one of the defined IEEE 754 decimal types (documentation is sparse here and I'm not very familiar with Swift myself; but this looks to be the case based on the APIs they expose and terms, like canonical, they use).

With that, at least item 2 from the original post wouldn't be applicable to System.Decimal and would instead only be applicable to some theoretical type that implemented the IEEE 754 decimal32, decimal64, or decimal128 types.
Item 1 and 3 are interesting proposals but are at least trivially handled today (just potentially slow), if you could open two separate API proposals roughly following the "good example" we have listed under step 1 of our API review process. You don't need every section, but providing the rationale/usages and proposed API sections at a minimum help with the overall review process and help detail why you feel they should be added and how they would get used in real world code.

@tannergooding tannergooding added api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Numerics and removed area-System.Runtime untriaged New issue has not been triaged by the area owner labels Mar 4, 2020
@charlesroddie
Copy link
Author

Sorry I've been slow about this. Allow rounding to negative decimal places: #35464

@tannergooding tannergooding added this to the Future milestone Jun 23, 2020
Copy link
Contributor

Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

This process is part of our issue cleanup automation.

@dotnet-policy-service dotnet-policy-service bot added backlog-cleanup-candidate An inactive issue that has been marked for automated closure. no-recent-activity labels Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Numerics backlog-cleanup-candidate An inactive issue that has been marked for automated closure. no-recent-activity
Projects
None yet
Development

No branches or pull requests

5 participants