Skip to content

Commit 6e46135

Browse files
committed
[stdlib] Update tests for generic floating-point conversion
1 parent 03903ae commit 6e46135

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

test/stdlib/FloatingPoint.swift.gyb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ FloatingPoint.test("BinaryFloatingPoint/genericFloatingPointConversion") {
206206
Float._convert(
207207
from: Double._convert(from: Float.leastNonzeroMagnitude).value).value,
208208
Float.leastNonzeroMagnitude)
209+
210+
// Let's make sure that the correct value is returned when two representable
211+
// values are equally close to the original value.
212+
let bitPattern: UInt64 = 0b01111111111_0000000000000000000000110000000000000000000000000000
213+
var z = Double(bitPattern: bitPattern)
214+
expectEqual(Float._convert(from: z).value, Float(z))
215+
216+
z = Double(Float.greatestFiniteMagnitude) +
217+
Double(Float.greatestFiniteMagnitude.ulp / 2)
218+
expectEqual(Float._convert(from: z).value, Float(z))
209219
}
210220

211221
func positiveOne<T: ExpressibleByIntegerLiteral>() -> T {

0 commit comments

Comments
 (0)