9 Conversion and promotion

This chapter covers

  • Conversion of one related type to another
  • How promotion finds the least common denominator among related types in an expression
  • Exploring the Julia standard library using the @edit macro

Julia and other mainstream programming languages handle arithmetic involving different number types so effortlessly that most of us likely don’t pay much attention to this fact:

julia> 3 + 4.2                    
7.2
 
julia> UInt8(5) + Int128(3e6)     
3000005
 
julia> 1//4 + 0.25
0.5

Numbers in the expression converted to floating-point numbers

All integers converted to Int128

In reality, doing this involves quite a lot of complexity. Under the hood, most programming languages have defined a set of promotion rules, which say what ...

Get Julia as a Second Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.