Skip to content

Commit cc1fe52

Browse files
committed
Fix sign bit shift
1 parent df393de commit cc1fe52

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

Tests/BinaryParsingTests/FloatingPointTests.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,22 @@ struct FloatingPointTests {
200200
let bytesBE = Array(bigEndian: value)
201201

202202
do {
203-
let value1 = try bytesLE.withParserSpan(Float80.init(parsingLittleEndian:))
203+
let value1 = try bytesLE.withParserSpan(
204+
Float80.init(parsingLittleEndian:))
204205
let value2 = try bytesLE.withParserSpan { input in
205206
try Float80(parsing: &input, endianness: .little)
206207
}
207208

208209
if value.isNaN {
209-
#expect(value1.isNaN)
210-
#expect(value2.isNaN)
210+
#expect(value1.isNaN, "little")
211+
#expect(value2.isNaN, "little")
211212
if value.isSignalingNaN {
212213
#expect(value1.isSignalingNaN)
213214
#expect(value2.isSignalingNaN)
214215
}
215216
} else {
216-
#expect(value1 == value)
217-
#expect(value2 == value)
217+
#expect(value1 == value, "little")
218+
#expect(value2 == value, "little")
218219
}
219220
}
220221

@@ -225,15 +226,15 @@ struct FloatingPointTests {
225226
}
226227

227228
if value.isNaN {
228-
#expect(value1.isNaN)
229-
#expect(value2.isNaN)
229+
#expect(value1.isNaN, "big")
230+
#expect(value2.isNaN, "big")
230231
if value.isSignalingNaN {
231232
#expect(value1.isSignalingNaN)
232233
#expect(value2.isSignalingNaN)
233234
}
234235
} else {
235-
#expect(value1 == value)
236-
#expect(value2 == value)
236+
#expect(value1 == value, "big")
237+
#expect(value2 == value, "big")
237238
}
238239
}
239240

Tests/BinaryParsingTests/TestingSupport.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ extension Array where Element == UInt8 {
146146
self.append(contentsOf: bytes)
147147
}
148148
let signAndExponent =
149-
value.exponentBitPattern | (value.sign == .minus ? 1 : 0 << 31)
149+
value.exponentBitPattern | ((value.sign == .minus ? 1 : 0) << 15)
150150
Swift.withUnsafeBytes(of: signAndExponent.littleEndian) { bytes in
151151
self.append(contentsOf: bytes)
152152
}
@@ -155,7 +155,7 @@ extension Array where Element == UInt8 {
155155
init(bigEndian value: Float80) {
156156
self = []
157157
let signAndExponent =
158-
value.exponentBitPattern | (value.sign == .minus ? 1 : 0 << 31)
158+
value.exponentBitPattern & 0x7FFF | ((value.sign == .minus ? 1 : 0) << 15)
159159
Swift.withUnsafeBytes(of: signAndExponent.bigEndian) { bytes in
160160
self.append(contentsOf: bytes)
161161
}

0 commit comments

Comments
 (0)