When an expression combines different number types, Julia determines a sensible common type before performing the operation. This process is promotion: it keeps arithmetic predictable without requiring every operation to implement every type combination separately. section 9.0 section 9.1
Mixed numeric values
Julia promotes the operands in `3 + 4.2` to a compatible floating-point representation and returns `7.2`. It also handles combinations such as `UInt8(5) + Int128(3e6)` and `1//4 + 0.25`.
Promotion is implemented through ordinary Julia functions rather than compiler-hardwired rules. Arithmetic methods call `promote`, which produces values of a common type before the final operation runs. Developers can extend the system by adding methods to `promote_rule` and related conversion functions. section 9.1 section 9.4
Inspect promotion directly with representative values:
- Use `@edit` to inspect the standard-library definitions behind arithmetic and promotion. section 9.1
Promotion supports custom numeric abstractions, including units such as degrees, radians, meters, feet, Celsius, and Fahrenheit. Combining promotion with conversion can make numerical code safer and support specialized accuracy, memory, or performance needs. section 9.0 section 9.4
