Skip to content

Conversation

DrusTheAxe
Copy link
Member

@DrusTheAxe DrusTheAxe commented Apr 28, 2025

Decimal data type (base-10 fixed-point math!)

This is implemented over the Win32 Decimal structure as the common data representation. C#'s System.Decimal uses the same representation in memory (different but equivalent implementation)

Recommendation is use your language's native decimal data type, if you've got one (C#, Python, ...). WinAppSDK supplements some languages to aid interop with the common data format (Decimal).

For some languages without a decimal data type WinAppSDK provides a native language data type for decimal operations and interop with the common data format. The C++ decimal class in decimal.h is an example of this.

For languages without a decimal data type WinAppSDK provides a runtimeclass Microsoft.Windows.Foundation.Decimal. This is only recommended when no other language native decimal type is available.

This is explained in more detail in specs\decimal\decimal.md. NOTE: This pre-draft is for early adopters to better understand the offering here. These APIs will stay EXPERIMENTAL until API Review is complete and whatever changes fall out of that are incorporated (could be minor, could be radical and majorly impactful).

NOTE: API Review will act on separate PR reviewing a future (review-ready) form of specs\decimal\decimal.md. This file is purely informational at this time and not to be taken today as definitive or API Review worthy.

@DrusTheAxe
Copy link
Member Author

/azp run

Copy link

Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

@DrusTheAxe
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

…o not search under root\Packages (for some reason the `Where...-notmatch $exclude` is performing a case-sensntive comparison when docs say it should be csae-insensitive. A little brute-force fix to prevent the pain
@DrusTheAxe
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@DrusTheAxe
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@DrusTheAxe
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@DrusTheAxe DrusTheAxe requested a review from jeffstall April 29, 2025 01:42
@sylveon
Copy link
Contributor

sylveon commented Apr 29, 2025

One thing I noticed is that Decimal is a boxed version of DecimalValue. This seems counter to the current practice where we have, for example Color, ColorHelper for static methods, and IReference<Color> for boxing. Why the divergence here?

@DrusTheAxe
Copy link
Member Author

One thing I noticed is that Decimal is a boxed version of DecimalValue. This seems counter to the current practice where we have, for example Color, ColorHelper for static methods, and IReference<Color> for boxing. Why the divergence here?

Unclear if/how that works given it must answer "How is DecimalValue handled by PropertyValue?"

https://learn.microsoft.com/en-us/uwp/api/windows.foundation.ireference-1

IReference inherits IPropertyValue. Types that implement IReference also implement the interface members of IPropertyValue.

Perhaps Color / ColorHelper / IReference<Color> is the better answer for DecimalValue / Decimal handling. The upside to experimental is one can experiment :-) You're the 2nd person to mention ColorHelper today so color <g> me intrigued. Need to do some more reading and perhaps throw together a DecimalHelper and related tests to answer some questions.

Can you think of another reference besides Color/ColorHelper using this pattern?

@sylveon
Copy link
Contributor

sylveon commented Apr 29, 2025

Can you think of another reference besides Color/ColorHelper using this pattern?

WF.GuidHelper, MUX.DurationHelper, MUX.CornerRadiusHelper, MUX.GridLengthHelper, MUX.PointHelper, MUX.RectHelper, MUX.SizeHelper, MUX.ThicknessHelper MUX.Media.MatrixHelper, etc.

As far as IReference<T> goes, the typical way to get one in C++ is to use winrt::box_value. I suppose a WASDK header would ship with the overload needed. @Sergio0694 would know best for cswinrt.

@Sergio0694
Copy link
Member

Sergio0694 commented Apr 29, 2025

For CsWinRT, we implement IReference<T> and IPropertyValue for every WinRT struct or delegate that exists. If you have any projected WinRT type (struct, enum, or delegate), or any custom mapped type (struct, enum, or delegate), whenever you marshal a boxed version of it we also add IPropertyValue and IReference<T> for it in the CCW vtable. The only difference compared to primitive types that IReferenceValue supports, is that it will report OtherType when you ask it "what are you?".

We would do the same, automatically, for DecimalValue as well, so that's not an issue.

@sylveon
Copy link
Contributor

sylveon commented Apr 29, 2025

Yeah, afaik cppwinrt has a basic implementation for other types, my main line of thought was the IPropertyValue member methods. If that's not necessary we can easily get away with using the regular implementation in cppwinrt instead of shipping a header.

@Sergio0694
Copy link
Member

To clarify I was agreeing with you that it'd be doable to do the same in CsWinRT if we just went with DecimalValue (and boxed), and DecimalHelpers. That was also my suggestion anyway, as it would avoid that "two boxed versions" issue you mentioned 🙂

@sylveon
Copy link
Contributor

sylveon commented Apr 29, 2025

If we go that way, I would rename it Decimal, but yeah :)

@DrusTheAxe DrusTheAxe merged commit 03b2316 into main Apr 29, 2025
27 checks passed
@DrusTheAxe DrusTheAxe deleted the user/drustheaxe/decimal branch April 29, 2025 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants