mirror of
https://github.com/apple/swift.git
synced 2026-12-04 11:15:15 +01:00
It appears that the implementation got copied from integer code. But, while `0-a` is a correct implementation of negation for integers, it is not for floating-point. (In particular, if `a` is zero, then `0-a` will be `+0` in the default rounding mode, which means that negating a zero vector gets the wrong sign). Use `-1 * a` instead. resolves: rdar://185854503
27 lines
651 B
Swift
27 lines
651 B
Swift
// RUN: %target-run-simple-swift
|
|
// REQUIRES: executable_test
|
|
// UNSUPPORTED: use_os_stdlib
|
|
|
|
import StdlibUnittest
|
|
|
|
let SIMDGenericFPTests = TestSuite("SIMD Generic FP")
|
|
|
|
func getNegativeZero<T>(of: T.Type) -> T
|
|
where T: SIMD, T.Scalar: BinaryFloatingPoint {
|
|
-T()
|
|
}
|
|
|
|
SIMDGenericFPTests.test("negation") {
|
|
let negZero = getNegativeZero(of: SIMD4<Float>.self)
|
|
expectEqual(negZero[0].sign, .minus)
|
|
expectEqual(negZero[1].sign, .minus)
|
|
expectEqual(negZero[2].sign, .minus)
|
|
expectEqual(negZero[3].sign, .minus)
|
|
expectEqual(negZero[0], 0)
|
|
expectEqual(negZero[1], 0)
|
|
expectEqual(negZero[2], 0)
|
|
expectEqual(negZero[3], 0)
|
|
}
|
|
|
|
runAllTests()
|