November 2017
Beginner
316 pages
6h 40m
English
In Julia, we don’t have type declarations that are applicable on a global scope. But we can definitely use them in the scope local to a function.
In the following example, we will define a function that has an x variable of the Int16 type. We are assigning it a value of 10000 (we will learn about functions and types in detail in the coming chapters):
julia> x = Int16(10000)10000julia> x*x-7936
This function is very straightforward. It assigns the value of 10000 to x of type Int16 and prints x*x.
Why do we get x*x, which is 10000*10000 as -7936?
This is because we exceeded the value that the type of the variable can handle. This resulted in a wraparound behavior. The wraparound behavior is part of the modular ...
Read now
Unlock full access