DEV Community

Cover image for Learning Julia(1): basics
Z. QIU
Z. QIU

Posted on • Updated on

Learning Julia(1): basics

Alt Text

Alt Text

#     one '#' symbole for a one-line comment, equal to // in C/C++

#=    '#=' + '=#' pair for multi-line comment
      similar to '/*'+'*/' pair in C/C++
=#

## as in java, println(xxx) is equivalent to print(xxx + '\n')


########   day 1:   Numbers
a = 1
println("a: ", a, ",", typeof(a))   ## Int64 if running on 64-bit CPU, Int32 for 32-bit CPU

aa = UInt8(1)     # method to convert to a specific type
println(a == aa)
println(sizeof(a), ", " ,sizeof(aa))

b = 3.2
println("b: ", b, ",", typeof(b))
println(sizeof(b))

c = 1e18
println("c: ", c, ",", typeof(c))

d = 0x3f
println("d: ", d, ",", typeof(d))

e = 0b10 
println("e: ", e, ",", typeof(e))

f = 0o057
println("f: ", f, ",", typeof(f))


g = 'x'
println("g: ", g, ",", typeof(g))
println("g-1: ", g-1, ",", typeof(g-1))
println(g == UInt8('x'))
g= convert( UInt8, g)  # convert function for converting types
println(g == UInt8('x'))

h = 2 + 3im
println("h: ", h, ", ", typeof(h))


i = 0.5f
println("i: ", i, ", ", typeof(i))

j = Inf - Inf
println("j: ", j, ", ", typeof(j))

k = Inf * 0
println("k: ", k, ", ", typeof(k))

l = 2/0
println("l: ", l, ", ", typeof(l))


m = 6//9

println("m: ", m, ", ", typeof(m))

n = bitstring(65535)
println("n: ", n, ", ", typeof(n))

Enter fullscreen mode Exit fullscreen mode

Below is the output that I got:
Alt Text

Top comments (0)