Exploring Swift’s numeric protocols
summary
Covers Swift’s numeric-protocol hierarchy, standard-library source use, and concrete surprises: integer initializers trap on overflow but Float80 yields infinity for out-of-range values; adding 0.1 ten times produces ~1.0001119 due to rounding. Shows practical tools: examining bitPattern and using ulp(of:) and nextUp to compute representable gaps, converting bitPattern to an integer for relative ULP comparisons, and writing protocol-constrained helpers (generic hypotenuse, slope classification, byte-to-binary-string) that actually work across Int/Float types.
AI-written summary · about
chapters (22)
- 0:00Intro
- 0:30Numbers
- 0:48Fundamental to computing
- 1:26Swift's numeric types
- 4:10Numeric Protocols
- 5:11protocol Binary Integer
- 7:21protocol Floating Point
- 9:38Semantics
- 10:04Mixing numeric types
- 10:36Type inference
- 11:20Previous example
- 13:37Extensions for our specific domain extension FloatingPoint
- 14:22Example: drawing line graphs
- 14:53small tweaks make a
- 20:20Integer representation
- 22:05Floating-point representation Float.pi
- 23:58Positive and negative zero
- 29:02Next representable Float
- 29:20Number Theory
- 32:14Next representable value: .nextUp protocol FloatingPoint !
- 33:30Comparing relative ULPs
- 35:28Precision is hard. Equality is harder.








