File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
Sources/FoundationEssentials/Decimal
Tests/FoundationEssentialsTests Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -236,6 +236,21 @@ extension Decimal /* : FloatingPoint */ {
236
236
}
237
237
238
238
public init ( sign: FloatingPointSign , exponent: Int , significand: Decimal ) {
239
+ #if FOUNDATION_FRAMEWORK
240
+ // Compatibility path
241
+ if Self . compatibility1 {
242
+ self . init (
243
+ _exponent: Int32 ( exponent) + significand. _exponent,
244
+ _length: significand. _length,
245
+ _isNegative: sign == . plus ? 0 : 1 ,
246
+ _isCompact: significand. _isCompact,
247
+ _reserved: 0 ,
248
+ _mantissa: significand. _mantissa
249
+ )
250
+ return
251
+ }
252
+ #endif
253
+
239
254
self = significand
240
255
do {
241
256
self = try significand. _multiplyByPowerOfTen (
Original file line number Diff line number Diff line change @@ -1159,9 +1159,21 @@ final class DecimalTests : XCTestCase {
1159
1159
var x = - 42 as Decimal
1160
1160
XCTAssertEqual ( x. significand. sign, . plus)
1161
1161
var y = Decimal ( sign: . plus, exponent: 0 , significand: x)
1162
+ #if FOUNDATION_FRAMEWORK
1163
+ if Decimal . compatibility1 {
1164
+ XCTAssertEqual ( y, 42 )
1165
+ y = Decimal ( sign: . minus, exponent: 0 , significand: x)
1166
+ XCTAssertEqual ( y, - 42 )
1167
+ } else {
1168
+ XCTAssertEqual ( y, - 42 )
1169
+ y = Decimal ( sign: . minus, exponent: 0 , significand: x)
1170
+ XCTAssertEqual ( y, 42 )
1171
+ }
1172
+ #else
1162
1173
XCTAssertEqual ( y, - 42 )
1163
1174
y = Decimal ( sign: . minus, exponent: 0 , significand: x)
1164
1175
XCTAssertEqual ( y, 42 )
1176
+ #endif
1165
1177
1166
1178
x = 42 as Decimal
1167
1179
XCTAssertEqual ( x. significand. sign, . plus)
You can’t perform that action at this time.
0 commit comments