-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariables.jl
More file actions
63 lines (50 loc) · 1.46 KB
/
variables.jl
File metadata and controls
63 lines (50 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using Printf
function variable_examples()
println("--------------------------------------")
println("variable_examples")
println("Variables types can be dynamically assigned")
s = 0
println(s)
s = true
println(s)
s = "Dog"
println(s)
println("We can also specify variable types")
x::Int8 = 10
println(x)
y::Int16 = -10
println(y)
# If we try to assign a different type to a typed variable, we get an exception
#y = 3.14
#println(y)
# Int8 : -128 - 127
# Int16 : −32,768 - 32,767
# Int32 : −2,147,483,648 - 2,147,483,647
# Int64 : −2^63 - 2^63 - 1
# Float32, Float64, UInt8, UInt16, etc.
# UInt8, UInt16, etc.
println("We can also use booleans")
somebool = true
println(somebool)
println("Chars have to be surrounded by single quotes")
c = 'c'
println(c)
println("Cast from Int to Char")
c2 = Char(120)
println(c2)
println("Cast from Float to Int")
i1 = UInt8(trunc(3.14))
println(i1)
println("Cast string to Float")
f1 = parse(Float64,"1")
println(f1)
println("Cast string to Int")
i2 = parse(Int8,"1")
println(i2)
println("We can also create BigInts")
someBigInt::BigInt = 1234 * 1234 * 1234 * 1234
println(someBigInt)
println("And we can create BigFloats")
someBigFloat::BigFloat = 1234 / 1234 / 1234 / 1234
println(someBigFloat)
end