File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -668,6 +668,7 @@ extension ${Self}: BinaryFloatingPoint {
668
668
public var significandWidth: Int {
669
669
let trailingZeros = significandBitPattern. countTrailingZeros
670
670
if isNormal {
671
+ guard significandBitPattern != 0 else { return 0 }
671
672
return ${ Self} . significandBitCount - trailingZeros
672
673
}
673
674
if isSubnormal {
Original file line number Diff line number Diff line change @@ -395,6 +395,18 @@ FloatingPoint.test("${Self}/LosslessStringConvertible") {
395
395
checkLosslessStringConvertible(instances)
396
396
expectTrue(Float(String(Float.nan))!.isNaN)
397
397
}
398
+
399
+ FloatingPoint.test("${Self}.significandWidth") {
400
+ expectEqual(-1, ${Self}(0).significandWidth)
401
+ expectEqual(-1, ${Self}.infinity.significandWidth)
402
+ expectEqual(-1, ${Self}.nan.significandWidth)
403
+ expectEqual(${Self}.significandBitCount, ${Self}(1).nextUp.significandWidth)
404
+ expectEqual(${Self}.significandBitCount, ${Self}(1).nextDown.significandWidth)
405
+ expectEqual(0, ${Self}.ulpOfOne.significandWidth)
406
+ expectEqual(0, ${Self}(1).significandWidth)
407
+ expectEqual(0, ${Self}(2).significandWidth)
408
+ expectEqual(1, ${Self}(3).significandWidth)
409
+ }
398
410
% if Self == 'Float80':
399
411
#endif
400
412
% end
You can’t perform that action at this time.
0 commit comments