Skip to content

Commit d32f51e

Browse files
authored
Revised Decimal data type (#5414)
* Replace winrt Decimal with DecimalHelper * Ran DevCheck -SyncDependencies * Rename Sub/Mul/Div/Mod to Subtract/Multiply/Divide/Modulo. Update spec * Added is_valid * More test coverage. Dropped unnecessary telemetry + TerminalVelocity files * Restore TerminalVelocity (needed for now). Update spec * Bug fixes * Test fix * Added HSTRING support for ABI folks * Updated spec
1 parent e573db6 commit d32f51e

18 files changed

Lines changed: 2092 additions & 1221 deletions

File tree

dev/Decimal/Decimal.idl

Lines changed: 75 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ namespace Microsoft.Windows.Foundation
88
[contractversion(1)]
99
apicontract DecimalContract{};
1010

11+
/// WinRT representation of the Win32 DECIMAL structure.
12+
/// @note This is the identical memory layout and encoding of the Win32 DECIMAL structure.
13+
/// The latter's definition is valid for COM but not WinRT making this equivalent structure necessary.
14+
/// @see https://learn.microsoft.com/windows/win32/api/wtypes/ns-wtypes-decimal-r1
1115
[feature(Feature_Decimal)]
1216
[contract(DecimalContract, 1)]
1317
struct DecimalValue
@@ -21,119 +25,100 @@ namespace Microsoft.Windows.Foundation
2125

2226
[feature(Feature_Decimal)]
2327
[contract(DecimalContract, 1)]
24-
runtimeclass Decimal : Windows.Foundation.IStringable
28+
runtimeclass DecimalHelper
2529
{
26-
Decimal();
27-
28-
static Decimal CreateFromBoolean(Boolean value);
29-
static Decimal CreateFromInt16(Int16 value);
30-
static Decimal CreateFromInt32(Int32 value);
31-
static Decimal CreateFromInt64(Int64 value);
32-
static Decimal CreateFromUInt8(UInt8 value);
33-
static Decimal CreateFromUInt16(UInt16 value);
34-
static Decimal CreateFromUInt32(UInt32 value);
35-
static Decimal CreateFromUInt64(UInt64 value);
36-
static Decimal CreateFromSingle(Single value);
37-
static Decimal CreateFromDouble(Double value);
38-
static Decimal CreateFromString(String value); // LCID=LOCALE_INVARIANT
39-
static Decimal CreateFromStringWithSystemDefaultLocale(String value); // LCID=GetSystemDefaultLCID()
40-
static Decimal CreateFromStringWithUserDefaultLocale(String value); // LCID=GetUserDefaultLCID()
41-
static Decimal CreateFromStringWithThreadLocale(String value); // LCID=GetThreadLocale()
42-
static Decimal CreateFromStringWithInvariantLocale(String value); // LCID=LOCALE_INVARIANT
43-
static Decimal Create(IInspectable value);
44-
static Decimal CreateFromDecimal(Decimal value);
45-
static Decimal CreateFromDecimalValue(DecimalValue value);
46-
47-
void SetFromBoolean(Boolean value);
48-
void SetFromInt16(Int16 value);
49-
void SetFromInt32(Int32 value);
50-
void SetFromInt64(Int64 value);
51-
void SetFromUInt8(UInt8 value);
52-
void SetFromUInt16(UInt16 value);
53-
void SetFromUInt32(UInt32 value);
54-
void SetFromUInt64(UInt64 value);
55-
void SetFromSingle(Single value);
56-
void SetFromDouble(Double value);
57-
void SetFromString(String value); // LCID=LOCALE_INVARIANT
58-
void SetFromStringWithSystemDefaultLocale(String value); // LCID=GetSystemDefaultLCID()
59-
void SetFromStringWithUserDefaultLocale(String value); // LCID=GetUserDefaultLCID()
60-
void SetFromStringWithThreadLocale(String value); // LCID=GetThreadLocale()
61-
void SetFromStringWithInvariantLocale(String value); // LCID=LOCALE_INVARIANT
62-
void Set(IInspectable value);
63-
void SetFromDecimal(Decimal value);
64-
void SetFromDecimalValue(DecimalValue value);
65-
66-
Boolean ToBoolean();
67-
Int16 ToInt16();
68-
Int32 ToInt32();
69-
Int64 ToInt64();
70-
UInt8 ToUInt8();
71-
UInt16 ToUInt16();
72-
UInt32 ToUInt32();
73-
UInt64 ToUInt64();
74-
Single ToSingle();
75-
Double ToDouble();
76-
//String ToString(); inherited from IStringable // LCID=LOCALE_INVARIANT
77-
String ToStringWithSystemDefaultLocale(); // LCID=GetSystemDefaultLCID()
78-
String ToStringWithUserDefaultLocale(); // LCID=GetUserDefaultLCID()
79-
String ToStringWithThreadLocale(); // LCID=GetThreadLocale()
80-
String ToStringWithInvariantLocale(); // LCID=LOCALE_INVARIANT
81-
IInspectable ToObject();
82-
Decimal ToDecimal(); //TODO: Rename to Copy(value) or Clone(value) ?
83-
DecimalValue ToDecimalValue();
84-
85-
/// Return true if (this == value).
86-
Boolean Equals(Decimal value);
87-
88-
/// Compare this decimal with value.
89-
/// @return 0 if this and value are equal, <0 if this is less than value or >0 if this is greater than value.
90-
Int32 Compare(Decimal value);
30+
static DecimalValue FromBoolean(Boolean value);
31+
static DecimalValue FromInt16(Int16 value);
32+
static DecimalValue FromInt32(Int32 value);
33+
static DecimalValue FromInt64(Int64 value);
34+
static DecimalValue FromUInt8(UInt8 value);
35+
static DecimalValue FromUInt16(UInt16 value);
36+
static DecimalValue FromUInt32(UInt32 value);
37+
static DecimalValue FromUInt64(UInt64 value);
38+
static DecimalValue FromSingle(Single value);
39+
static DecimalValue FromDouble(Double value);
40+
static DecimalValue FromString(String value); // LCID=LOCALE_INVARIANT
41+
static DecimalValue FromStringWithSystemDefaultLocale(String value); // LCID=GetSystemDefaultLCID()
42+
static DecimalValue FromStringWithUserDefaultLocale(String value); // LCID=GetUserDefaultLCID()
43+
static DecimalValue FromStringWithThreadLocale(String value); // LCID=GetThreadLocale()
44+
45+
static Boolean ToBoolean(DecimalValue value);
46+
static Int16 ToInt16(DecimalValue value);
47+
static Int32 ToInt32(DecimalValue value);
48+
static Int64 ToInt64(DecimalValue value);
49+
static UInt8 ToUInt8(DecimalValue value);
50+
static UInt16 ToUInt16(DecimalValue value);
51+
static UInt32 ToUInt32(DecimalValue value);
52+
static UInt64 ToUInt64(DecimalValue value);
53+
static Single ToSingle(DecimalValue value);
54+
static Double ToDouble(DecimalValue value);
55+
static String ToString(DecimalValue value); // LCID=LOCALE_INVARIANT
56+
static String ToStringWithSystemDefaultLocale(DecimalValue value); // LCID=GetSystemDefaultLCID()
57+
static String ToStringWithUserDefaultLocale(DecimalValue value); // LCID=GetUserDefaultLCID()
58+
static String ToStringWithThreadLocale(DecimalValue value); // LCID=GetThreadLocale()
59+
60+
/// Return true if (left == right).
61+
static Boolean Equals(DecimalValue left, DecimalValue right);
62+
63+
/// Compare decimal values.
64+
/// @return 0 if left and right are equal, <0 if left is less than right or >0 if left is greater than right.
65+
static Int32 Compare(DecimalValue left, DecimalValue right);
66+
67+
/// Return true if the value is valid.
68+
static Boolean IsValid(DecimalValue value);
9169

9270
/// Return the scaling factor of the value (the number of decimal digits).
9371
/// @return the scaling factor, ranging from 0 to max_scale().
94-
UInt32 Scale { get; };
72+
static UInt32 Scale(DecimalValue value);
9573

9674
/// Return the sign of the value.
97-
/// @return 0 if this os zero, <0 if this is less than zero or >0 if this is greater than zero.
98-
Int32 Sign { get; };
75+
/// @return 0 if value is zero, <0 if value is less than zero or >0 if value is greater than zero.
76+
static Int32 Sign(DecimalValue value);
9977

10078
/// Return the maximum scaling factor
101-
static UInt32 MaxScale{ get; };
79+
static UInt32 MaxScale();
10280

10381
/// Return the maximum value (79,228,162,514,264,337,593,543,950,335).
104-
static Decimal MaxValue{ get; };
82+
static DecimalValue MaxValue();
10583

10684
/// Return the minimum value (-79,228,162,514,264,337,593,543,950,335).
107-
static Decimal MinValue{ get; };
85+
static DecimalValue MinValue();
10886

109-
/// Return a decimal whose value is (-this).
110-
Decimal Negate();
87+
/// Return a decimal whose value is (-value).
88+
static DecimalValue Negate(DecimalValue value);
11189

11290
/// Return the absolute value.
113-
Decimal Abs();
91+
static DecimalValue Abs(DecimalValue value);
11492

115-
/// Return the value's integer portion (zero to the right of the decimal point).
116-
Decimal Fix();
93+
/// Return the integral digits; any fractional digits are discarded.
94+
static DecimalValue Truncate(DecimalValue value);
11795

118-
/// Return the value rounded down to the nearest integer.
119-
Decimal Integer();
96+
/// Return the integral digits rounded down to -infinity; any fractional digits are discarded.
97+
static DecimalValue Floor(DecimalValue value);
98+
99+
/// Return the integral digits rounded up to +infinity; any fractional digits are discarded.
100+
static DecimalValue Ceiling(DecimalValue value);
120101

121102
/// Return the value rounded to the specific number of decimal places.
122-
Decimal Round(Int32 decimalPlaces);
103+
static DecimalValue Round(DecimalValue value, Int32 decimalPlaces);
104+
105+
/// Return value clamped to the inclusive range of min and max.
106+
/// @return value if min <= value <= max, or min if value < min, or max if max < value.
107+
static DecimalValue Clamp(DecimalValue value, DecimalValue min, DecimalValue max);
123108

124-
/// Returns a Decimal whose value is (this + value).
125-
Decimal Add(Decimal value);
109+
/// Returns a DecimalValue whose value is (left + right).
110+
static DecimalValue Add(DecimalValue left, DecimalValue right);
126111

127-
/// Returns a Decimal whose value is (this - value).
128-
Decimal Sub(Decimal value);
112+
/// Returns a DecimalValue whose value is (left - right).
113+
static DecimalValue Subtract(DecimalValue left, DecimalValue right);
129114

130-
/// Returns a Decimal whose value is (this * value).
131-
Decimal Mul(Decimal value);
115+
/// Returns a DecimalValue whose value is (left * right).
116+
static DecimalValue Multiply(DecimalValue left, DecimalValue right);
132117

133-
/// Returns a Decimal whose value is (this / value).
134-
Decimal Div(Decimal value);
118+
/// Returns a DecimalValue whose value is (left / right).
119+
static DecimalValue Divide(DecimalValue left, DecimalValue right);
135120

136-
/// Returns a Decimal whose value is (this % value).
137-
Decimal Mod(Decimal value);
121+
/// Returns a DecimalValue whose value is (left % right).
122+
static DecimalValue Modulo(DecimalValue left, DecimalValue right);
138123
}
139124
}

dev/Decimal/Decimal.vcxitems

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
<ProjectCapability Include="SourceItemsFromImports" />
1515
</ItemGroup>
1616
<ItemGroup>
17-
<ClCompile Include="$(MSBuildThisFileDirectory)M.W.F.Decimal.cpp" />
17+
<ClCompile Include="$(MSBuildThisFileDirectory)M.W.F.DecimalHelper.cpp" />
1818
</ItemGroup>
1919
<ItemGroup>
20-
<ClInclude Include="$(MSBuildThisFileDirectory)M.W.F.Decimal.h" />
21-
<ClInclude Include="$(MSBuildThisFileDirectory)M.W.F.DecimalTelemetry.h" />
20+
<ClInclude Include="$(MSBuildThisFileDirectory)M.W.F.DecimalHelper.h" />
2221
<ClInclude Include="$(MSBuildThisFileDirectory)pch.h" />
2322
</ItemGroup>
2423
<ItemGroup>
@@ -27,6 +26,5 @@
2726
<ItemGroup>
2827
<PublicHeaders Include="$(MSBuildThisFileDirectory)decimal.h" />
2928
<PublicHeaders Include="$(MSBuildThisFileDirectory)decimalcppwinrt.h" />
30-
<PublicHeaders Include="$(MSBuildThisFileDirectory)..\common\TerminalVelocityFeatures-Decimal.h" />
3129
</ItemGroup>
3230
</Project>

dev/Decimal/Decimal.vcxitems.filters

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@
1111
</Filter>
1212
</ItemGroup>
1313
<ItemGroup>
14-
<ClCompile Include="$(MSBuildThisFileDirectory)M.W.F.Decimal.cpp">
14+
<ClCompile Include="$(MSBuildThisFileDirectory)M.W.F.DecimalHelper.cpp">
1515
<Filter>Source Files</Filter>
1616
</ClCompile>
1717
</ItemGroup>
1818
<ItemGroup>
19-
<ClInclude Include="$(MSBuildThisFileDirectory)M.W.F.Decimal.h">
20-
<Filter>Header Files</Filter>
21-
</ClInclude>
22-
<ClInclude Include="$(MSBuildThisFileDirectory)M.W.F.DecimalTelemetry.h">
19+
<ClInclude Include="$(MSBuildThisFileDirectory)M.W.F.DecimalHelper.h">
2320
<Filter>Header Files</Filter>
2421
</ClInclude>
2522
<ClInclude Include="$(MSBuildThisFileDirectory)pch.h">

dev/Decimal/DecimalTelemetry.h

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)