🤯 204 + 102 / 2 = 255 in Swift. And it's a bug.
➗ Division binds tighter than +, so Swift computes 204 + 51.
✅ The average you wanted: (204 + 102) / 2 = 153.
🔇 No error. No warning. It just looks reasonable.
🧮 Bonus trap: integer division drops the remainder.
255 / 2 = 127 → 7F, not 80.
🧵
🤯 204 + 102 / 2 = 255 in Swift. And it's a bug. ➗ Division binds tighter than +, so Swift computes 204 + 51. ✅ The average you wanted: (204 + 102) / 2 = 153. 🔇 No error. No warning. It just looks reasonable. 🧮 Bonus trap: integer division drops the remainder. 255 / 2 = 127 → 7F, not 80. 🧵
0 vue
Publié le 23/11/2026 03:58
1:11
🤯 204 + 102 / 2 = 255 in Swift. And it's a bug.
➗ Division binds tighter than +, so Swift computes 204 + 51.
✅ The average you wanted: (204 + 102) / 2 = 153.
🔇 No error. No warning. It just looks reasonable.
🧮 Bonus trap: integer division drops the remainder.
255 / 2 = 127 → 7F, not 80.
🧵
🎯 Rule: parentheses aren't decoration. Write the grouping you mean.
🎓 Want to learn more? Check Mastering Swift from Beginner 👇
www.udemy.com/course/swift...