Edge case enum

Found the equivalent edge case that doesn't use Strings and behaves exactly the same way:

enum F: Double {
    case x = -0.0
    case y = 0.0
}

var x = F.x
var y = F.y
var xraw = x.rawValue
var yraw = y.rawValue
print(xraw == yraw) // true
dumpHex(&x, MemoryLayout.size(ofValue: x)) // 00
dumpHex(&y, MemoryLayout.size(ofValue: y)) // 01
dumpHex(&xraw, MemoryLayout.size(ofValue: xraw)) // 00 00 00 00 00 00 00 80
dumpHex(&yraw, MemoryLayout.size(ofValue: yraw)) // 00 00 00 00 00 00 00 00
print(x == y) // true! unexpected
4 Likes