Files
swift-mirror/test/1_stdlib/FloatingPoint.swift.gyb

671 lines
29 KiB
Plaintext

// RUN: rm -rf %t && mkdir -p %t && %S/../../utils/gyb %s -o %t/FloatingPoint.swift
// RUN: %S/../../utils/line-directive %t/FloatingPoint.swift -- %target-build-swift -parse-stdlib -Xfrontend -disable-access-control %t/FloatingPoint.swift -o %t/a.out
// RUN: %S/../../utils/line-directive %t/FloatingPoint.swift -- %target-run %t/a.out
// REQUIRES: executable_test
// XFAIL: interpret
import Swift
import StdlibUnittest
// Also import modules which are used by StdlibUnittest internally. This
// workaround is needed to link all required libraries in case we compile
// StdlibUnittest with -sil-serialize-all.
import SwiftPrivate
#if _runtime(_ObjC)
import ObjectiveC
#endif
#if arch(i386) || arch(x86_64)
struct Float80Bits : Equatable, CustomStringConvertible {
var signAndExponent: UInt16
var significand: UInt64
init(_ signAndExponent: UInt16, _ significand: UInt64) {
self.signAndExponent = signAndExponent
self.significand = significand
}
var description: String {
return "(\(String(signAndExponent, radix: 16)) \(String(significand, radix: 16))))"
}
}
func == (lhs: Float80Bits, rhs: Float80Bits) -> Bool {
return
lhs.signAndExponent == rhs.signAndExponent &&
lhs.significand == rhs.significand
}
extension Float80 {
func _toBitPattern() -> Float80Bits {
let bits = Builtin.bitcast_FPIEEE80_Int80(self._value)
let sixtyFour = Builtin.zextOrBitCast_Int64_Int80((64 as Int64)._value)
return Float80Bits(
UInt16(Builtin.truncOrBitCast_Int80_Int16(
Builtin.lshr_Int80(bits, sixtyFour))),
UInt64(Builtin.truncOrBitCast_Int80_Int64(bits)))
}
static func _fromBitPattern(bits: Float80Bits) -> Float80 {
var result = Builtin.shl_Int80(
Builtin.zextOrBitCast_Int16_Int80(bits.signAndExponent._value),
Builtin.zextOrBitCast_Int64_Int80((64 as Int64)._value))
result = Builtin.or_Int80(
result, Builtin.zextOrBitCast_Int64_Int80(bits.significand._value))
return Float80(_bits: Builtin.bitcast_Int80_FPIEEE80(result))
}
}
#endif
var FloatingPoint = TestSuite("FloatingPoint")
func positiveOne<T: IntegerLiteralConvertible>() -> T {
return 1
}
func negativeOne<T: IntegerLiteralConvertible>() -> T {
return -1
}
FloatingPoint.test("Float/IntegerLiteralConvertible") {
expectEqual(positiveOne(), 1.0 as Float)
expectEqual(negativeOne(), -1.0 as Float)
}
// Tests the float and int conversions work correctly. Each case is special.
FloatingPoint.test("Float/UInt8") {
expectEqual(UInt8.min, UInt8(Float(UInt8.min)))
expectEqual(UInt8.max, UInt8(Float(UInt8.max)))
}
FloatingPoint.test("Float/Int8") {
expectEqual(Int8.min, Int8(Float(Int8.min)))
expectEqual(Int8.max, Int8(Float(Int8.max)))
}
FloatingPoint.test("Float/UInt16") {
expectEqual(UInt16.min, UInt16(Float(UInt16.min)))
expectEqual(UInt16.max, UInt16(Float(UInt16.max)))
}
FloatingPoint.test("Float/Int16") {
expectEqual(Int16.min, Int16(Float(Int16.min)))
expectEqual(Int16.max, Int16(Float(Int16.max)))
}
FloatingPoint.test("Float/UInt32") {
expectEqual(UInt32.min, UInt32(Float(UInt32.min)))
expectCrashLater()
expectEqual(UInt32.max, UInt32(Float(UInt32.max)))
}
FloatingPoint.test("Float/Int32") {
expectEqual(Int32.min, Int32(Float(Int32.min)))
expectCrashLater()
expectEqual(Int32.max, Int32(Float(Int32.max)))
}
FloatingPoint.test("Float/UInt64") {
expectEqual(UInt64.min, UInt64(Float(UInt64.min)))
expectCrashLater()
expectEqual(UInt64.max, UInt64(Float(UInt64.max)))
}
FloatingPoint.test("Float/Int64") {
expectEqual(Int64.min, Int64(Float(Int64.min)))
expectCrashLater()
expectEqual(Int64.max, Int64(Float(Int64.max)))
}
FloatingPoint.test("Double/IntegerLiteralConvertible") {
expectEqual(positiveOne(), 1.0 as Double)
expectEqual(negativeOne(), -1.0 as Double)
}
FloatingPoint.test("Double/UInt8") {
expectEqual(UInt8.min, UInt8(Double(UInt8.min)))
expectEqual(UInt8.max, UInt8(Double(UInt8.max)))
}
FloatingPoint.test("Double/Int8") {
expectEqual(Int8.min, Int8(Double(Int8.min)))
expectEqual(Int8.max, Int8(Double(Int8.max)))
}
FloatingPoint.test("Double/UInt16") {
expectEqual(UInt16.min, UInt16(Double(UInt16.min)))
expectEqual(UInt16.max, UInt16(Double(UInt16.max)))
}
FloatingPoint.test("Double/Int16") {
expectEqual(Int16.min, Int16(Double(Int16.min)))
expectEqual(Int16.max, Int16(Double(Int16.max)))
}
FloatingPoint.test("Double/UInt32") {
expectEqual(UInt32.min, UInt32(Double(UInt32.min)))
expectEqual(UInt32.max, UInt32(Double(UInt32.max)))
}
FloatingPoint.test("Double/Int32") {
expectEqual(Int32.min, Int32(Double(Int32.min)))
expectEqual(Int32.max, Int32(Double(Int32.max)))
}
FloatingPoint.test("Double/UInt64") {
expectEqual(UInt64.min, UInt64(Double(UInt64.min)))
expectCrashLater()
expectEqual(UInt64.max, UInt64(Double(UInt64.max)))
}
FloatingPoint.test("Double/Int64") {
expectEqual(Int64.min, Int64(Double(Int64.min)))
expectCrashLater()
expectEqual(Int64.max, Int64(Double(Int64.max)))
}
FloatingPoint.test("Float/HashValueZero") {
let zero: Float = getFloat32(0.0)
let negativeZero: Float = getFloat32(-0.0)
expectNotEqual(zero._toBitPattern(), negativeZero._toBitPattern())
expectEqual(zero.hashValue, negativeZero.hashValue)
}
FloatingPoint.test("Double/HashValueZero") {
let zero: Double = getFloat64(0.0)
let negativeZero: Double = getFloat64(-0.0)
expectNotEqual(zero._toBitPattern(), negativeZero._toBitPattern())
expectEqual(zero.hashValue, negativeZero.hashValue)
}
#if arch(i386) || arch(x86_64)
FloatingPoint.test("Float80/IntegerLiteralConvertible") {
expectEqual(positiveOne(), 1.0 as Float80)
expectEqual(negativeOne(), -1.0 as Float80)
}
FloatingPoint.test("Float80/HashValueZero") {
let zero: Float80 = getFloat80(0.0)
let negativeZero: Float80 = getFloat80(-0.0)
expectNotEqual(zero._toBitPattern(), negativeZero._toBitPattern())
expectEqual(zero.hashValue, negativeZero.hashValue)
}
#endif
func getPositiveSubnormal_Float32() -> Float32 {
var result: Float32 = 1.0
for _ in 0..<127 {
result /= 2.0 as Float32
}
expectTrue(result.isSubnormal)
return result
}
func getPositiveSubnormal_Float64() -> Float64 {
var result: Float64 = 1.0
for _ in 0..<1023 {
result /= 2.0 as Float64
}
expectTrue(result.isSubnormal)
return result
}
// FIXME: Float80
// <rdar://problem/17958458> Int(Float80.quietNaN) is garbage
% for FloatSelf in ['Float32', 'Float64']:
func checkFloatingPointComparison_${FloatSelf}(
expected: ExpectedComparisonResult,
_ lhs: ${FloatSelf}, _ rhs: ${FloatSelf},
//===--- TRACE boilerplate ----------------------------------------------===//
// @autoclosure _ message: () -> String = "",
showFrame: Bool = true,
stackTrace: SourceLocStack = SourceLocStack(),
file: String = #file, line: UInt = #line
) {
let newTrace = stackTrace.pushIf(showFrame, file: file, line: line)
let message = { "expected: lhs=\(lhs) \(expected) rhs=\(rhs)" }
expectEqual(expected.isEQ(), lhs == rhs, message(), stackTrace: newTrace)
expectEqual(expected.isNE(), lhs != rhs, message(), stackTrace: newTrace)
checkHashable(expected.isEQ(), lhs, rhs, message(), stackTrace: newTrace)
expectEqual(expected.isLT(), lhs < rhs, message(), stackTrace: newTrace)
expectEqual(expected.isLE(), lhs <= rhs, message(), stackTrace: newTrace)
expectEqual(expected.isGE(), lhs >= rhs, message(), stackTrace: newTrace)
expectEqual(expected.isGT(), lhs > rhs, message(), stackTrace: newTrace)
checkComparable(expected, lhs, rhs, message(), stackTrace: newTrace)
}
FloatingPoint.test("${FloatSelf}/{Comparable,Hashable,Equatable}") {
// On arm we flush subnormals to zero so testing subnormals won't work.
#if arch(arm)
let interestingValues: [${FloatSelf}] = [
// Interesting floating point values, sorted.
-${FloatSelf}.infinity,
-1.0,
-0.0,
0.0,
1.0,
${FloatSelf}.infinity,
${FloatSelf}.quietNaN,
]
#else
let interestingValues: [${FloatSelf}] = [
// Interesting floating point values, sorted.
-${FloatSelf}.infinity,
-1.0,
-getPositiveSubnormal_${FloatSelf}(),
-0.0,
0.0,
getPositiveSubnormal_${FloatSelf}(),
1.0,
${FloatSelf}.infinity,
${FloatSelf}.quietNaN,
]
#endif
for lhsIdx in interestingValues.indices {
for rhsIdx in interestingValues.indices {
let lhs = interestingValues[lhsIdx]
let rhs = interestingValues[rhsIdx]
if lhs.isZero && rhs.isZero {
// Special case: 0.0 and -0.0 compare equal.
checkFloatingPointComparison_${FloatSelf}(
ExpectedComparisonResult.eq, lhs, rhs)
} else if lhs.isNaN || rhs.isNaN {
// Special case: NaN is unordered wrt other values.
// - equality comparison with NaN returns false,
// - NaN is not equal to anything, including NaN.
expectFalse(lhs == rhs)
expectTrue(lhs != rhs)
expectFalse(lhs < rhs)
expectFalse(lhs <= rhs)
expectFalse(lhs >= rhs)
expectFalse(lhs > rhs)
} else {
// The sane case.
checkFloatingPointComparison_${FloatSelf}(
lhsIdx < rhsIdx ?
ExpectedComparisonResult.lt :
(lhsIdx == rhsIdx ?
ExpectedComparisonResult.eq :
ExpectedComparisonResult.gt),
lhs, rhs)
}
}
}
}
% end
% for Self in ['Float32', 'Float64', 'Float80']:
#if ${'arch(i386) || arch(x86_64)' if Self == 'Float80' else 'true'}
FloatingPoint.test("${Self}/Strideable") {
// FIXME: the test data could probably be better chosen here, to
// exercise more cases. Note: NaNs (and possibly Infs) are singular
// values with respect to Strideable conformance and aren't expected
// to pass these tests.
let instances: [${Self}] = [-1.0, 0.0, 0.5, 1.0, 1E20]
checkStrideable(
instances, strides: instances,
distanceOracle: { instances[$1] - instances[$0] },
advanceOracle: { instances[$0] + instances[$1] })
}
#endif
% end
// FIXME: implement Float80 tests after Float80 is implemented.
// <rdar://problem/20005438> Float80 does not conform to FloatingPoint
FloatingPoint.test("Float32/Literals") {
do {
let f: Float32 = 0.0
expectEqual(0x0000_0000, f._toBitPattern())
}
do {
let f: Float32 = -0.0
expectEqual(0x8000_0000, f._toBitPattern())
}
do {
let f: Float32 = 1.0
expectEqual(0x3f80_0000, f._toBitPattern())
}
do {
let f: Float32 = -1.0
expectEqual(0xbf80_0000, f._toBitPattern())
}
do {
let f: Float32 = 0.999999
expectEqual(0x3f7fffef, f._toBitPattern())
}
do {
let f: Float32 = 0.9999999
expectEqual(0x3f7ffffe, f._toBitPattern())
}
do {
let f: Float32 = 0.99999999
expectEqual(0x3f80_0000, f._toBitPattern())
}
// Infinity.
// FIXME: this should be a compile-time error, not silent overflow.
do {
let f: Float32 = 1.0e999
expectEqual(0x7f80_0000, f._toBitPattern())
}
do {
let f: Float32 = -1.0e999
expectEqual(0xff80_0000, f._toBitPattern())
}
// Smallest subnormal.
do {
let f: Float32 = 1.4e-45
expectEqual(0x0000_0001, f._toBitPattern())
}
do {
let f: Float32 = -1.4e-45
expectEqual(0x8000_0001, f._toBitPattern())
}
// Rounded to zero.
do {
let f: Float32 = 0.7e-45
expectEqual(0x0000_0000, f._toBitPattern())
}
do {
let f: Float32 = -0.7e-45
expectEqual(0x8000_0000, f._toBitPattern())
}
// Second largest normal.
do {
let f: Float32 = 3.4028232e+38
expectEqual(0x7f7f_fffe, f._toBitPattern())
}
do {
let f: Float32 = -3.4028232e+38
expectEqual(0xff7f_fffe, f._toBitPattern())
}
// Largest normal.
do {
let f: Float32 = 3.4028234e+38
expectEqual(0x7f7f_ffff, f._toBitPattern())
}
do {
let f: Float32 = 340282340000000000000000000000000000000.0
expectEqual(0x7f7f_ffff, f._toBitPattern())
}
do {
let f: Float32 = 340282340000000000000000000000000000000
expectEqual(0x7f7f_ffff, f._toBitPattern())
}
do {
let f: Float32 = -3.4028234e+38
expectEqual(0xff7f_ffff, f._toBitPattern())
}
do {
let f: Float32 = -340282340000000000000000000000000000000.0
expectEqual(0xff7f_ffff, f._toBitPattern())
}
do {
let f: Float32 = -340282340000000000000000000000000000000
expectEqual(0xff7f_ffff, f._toBitPattern())
}
// Smallest decimal that is rounded to infinity.
// FIXME: this should be a compile-time error, not silent overflow.
do {
let f: Float32 = 3.4028236e+38
expectEqual(0x7f80_0000, f._toBitPattern())
}
do {
let f: Float32 = -3.4028236e+38
expectEqual(0xff80_0000, f._toBitPattern())
}
}
FloatingPoint.test("Float64/Literals") {
do {
let f: Float64 = 0.0
expectEqual(0x0000_0000_0000_0000, f._toBitPattern())
}
do {
let f: Float64 = -0.0
expectEqual(0x8000_0000_0000_0000, f._toBitPattern())
}
do {
let f: Float64 = 1.0
expectEqual(0x3ff0_0000_0000_0000, f._toBitPattern())
}
do {
let f: Float64 = -1.0
expectEqual(0xbff0_0000_0000_0000, f._toBitPattern())
}
do {
let f: Float64 = 0.999999999999999
expectEqual(0x3fef_ffff_ffff_fff7, f._toBitPattern())
}
do {
let f: Float64 = 0.9999999999999999
expectEqual(0x3fef_ffff_ffff_ffff, f._toBitPattern())
}
do {
let f: Float64 = 0.99999999999999999
expectEqual(0x3ff0_0000_0000_0000, f._toBitPattern())
}
// Infinity.
// FIXME: this should be a compile-time error, not silent overflow.
do {
let f: Float64 = 1.0e999
expectEqual(0x7ff0_0000_0000_0000, f._toBitPattern())
}
do {
let f: Float64 = -1.0e999
expectEqual(0xfff0_0000_0000_0000, f._toBitPattern())
}
// Smallest subnormal.
do {
let f: Float64 = 4.0e-324
expectEqual(0x0000_0000_0000_0001, f._toBitPattern())
}
do {
let f: Float64 = -4.0e-324
expectEqual(0x8000_0000_0000_0001, f._toBitPattern())
}
// Rounded to zero.
do {
let f: Float64 = 2.4e-324
expectEqual(0x0000_0000_0000_0000, f._toBitPattern())
}
do {
let f: Float64 = -2.4e-324
expectEqual(0x8000_0000_0000_0000, f._toBitPattern())
}
// Second largest normal.
do {
let f: Float64 = 1.79769313486231551e+308
expectEqual(0x7fef_ffff_ffff_fffe, f._toBitPattern())
}
do {
let f: Float64 = -1.79769313486231551e+308
expectEqual(0xffef_ffff_ffff_fffe, f._toBitPattern())
}
// Largest normal.
do {
let f: Float64 = 1.7976931348623157e+308
expectEqual(0x7fef_ffff_ffff_ffff, f._toBitPattern())
}
do {
let f: Float64 = 179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0
expectEqual(0x7fef_ffff_ffff_ffff, f._toBitPattern())
}
do {
let f: Float64 = 179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
expectEqual(0x7fef_ffff_ffff_ffff, f._toBitPattern())
}
do {
let f: Float64 = -1.7976931348623157e+308
expectEqual(0xffef_ffff_ffff_ffff, f._toBitPattern())
}
do {
let f: Float64 = -179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0
expectEqual(0xffef_ffff_ffff_ffff, f._toBitPattern())
}
do {
let f: Float64 = -179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
expectEqual(0xffef_ffff_ffff_ffff, f._toBitPattern())
}
// Smallest decimal that is rounded to infinity.
// FIXME: this should be a compile-time error, not silent overflow.
do {
let f: Float64 = 1.7976931348623159e+308
expectEqual(0x7ff0_0000_0000_0000, f._toBitPattern())
}
do {
let f: Float64 = -1.7976931348623159e+308
expectEqual(0xfff0_0000_0000_0000, f._toBitPattern())
}
}
#if arch(i386) || arch(x86_64)
FloatingPoint.test("Float80/Literals") {
do {
let f: Float80 = 0.0
expectEqual(Float80Bits(0x0000, 0x0000_0000_0000_0000), f._toBitPattern())
}
do {
let f: Float80 = -0.0
expectEqual(Float80Bits(0x8000, 0x0000_0000_0000_0000), f._toBitPattern())
}
do {
let f: Float80 = 1.0
expectEqual(Float80Bits(0x3fff, 0x8000_0000_0000_0000), f._toBitPattern())
}
do {
let f: Float80 = -1.0
expectEqual(Float80Bits(0xbfff, 0x8000_0000_0000_0000), f._toBitPattern())
}
do {
let f: Float80 = 0.999999999999999999
expectEqual(Float80Bits(0x3ffe, 0xffff_ffff_ffff_ffee), f._toBitPattern())
}
do {
let f: Float80 = 0.9999999999999999999
expectEqual(Float80Bits(0x3ffe, 0xffff_ffff_ffff_fffe), f._toBitPattern())
}
do {
let f: Float80 = 0.99999999999999999995
expectEqual(Float80Bits(0x3ffe, 0xffff_ffff_ffff_ffff), f._toBitPattern())
}
do {
let f: Float80 = 0.99999999999999999999
expectEqual(Float80Bits(0x3fff, 0x8000_0000_0000_0000), f._toBitPattern())
}
// Infinity.
// FIXME: this should be a compile-time error, not silent overflow.
do {
let f: Float80 = 1.0e19999
expectEqual(Float80Bits(0x7fff, 0x8000_0000_0000_0000), f._toBitPattern())
}
do {
let f: Float80 = -1.0e19999
expectEqual(Float80Bits(0xffff, 0x8000_0000_0000_0000), f._toBitPattern())
}
// Smallest subnormal.
do {
// 3.645199531882474602528e-4951
let f: Float80 = 3.6e-4951
expectEqual(Float80Bits(0x0000, 0x0000_0000_0000_0001), f._toBitPattern())
}
do {
let f: Float80 = -3.6e-4951
expectEqual(Float80Bits(0x8000, 0x0000_0000_0000_0001), f._toBitPattern())
}
// Rounded to zero.
do {
let f: Float80 = 1.8e-4951
expectEqual(Float80Bits(0x0000, 0x0000_0000_0000_0000), f._toBitPattern())
}
do {
let f: Float80 = -1.8e-4951
expectEqual(Float80Bits(0x8000, 0x0000_0000_0000_0000), f._toBitPattern())
}
// Largest normal.
do {
let f: Float80 = 1.189731495357231765e+4932
expectEqual(Float80Bits(0x7ffe, 0xffff_ffff_ffff_ffff), f._toBitPattern())
}
do {
let f: Float80 = 1189731495357231765000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0
expectEqual(Float80Bits(0x7ffe, 0xffff_ffff_ffff_ffff), f._toBitPattern())
}
do {
let f: Float80 = -1.189731495357231765e+4932
expectEqual(Float80Bits(0xfffe, 0xffff_ffff_ffff_ffff), f._toBitPattern())
}
do {
let f: Float80 = -1189731495357231765000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0
expectEqual(Float80Bits(0xfffe, 0xffff_ffff_ffff_ffff), f._toBitPattern())
}
// Smallest decimal that is rounded to infinity.
// FIXME: this should be a compile-time error, not silent overflow.
do {
let f: Float80 = 1.18973149535723176515e+4932
expectEqual(Float80Bits(0x7fff, 0x8000_0000_0000_0000), f._toBitPattern())
}
do {
let f: Float80 = -1.18973149535723176515e+4932
expectEqual(Float80Bits(0xffff, 0x8000_0000_0000_0000), f._toBitPattern())
}
}
#endif
var FloatingPointClassification = TestSuite("NumericParsing")
FloatingPointClassification.test("FloatingPointClassification/Equatable") {
let values: [FloatingPointClassification] = [
.signalingNaN,
.quietNaN,
.negativeInfinity,
.negativeNormal,
.negativeSubnormal,
.negativeZero,
.positiveZero,
.positiveSubnormal,
.positiveNormal,
.positiveInfinity
]
// Values should be equal iff indices equal
checkEquatable(values, oracle: { $0 == $1 })
}
runAllTests()