In [1]:
a = 1 + 1
Out[1]:
In [2]:
b = "hola mundo"
Out[2]:
In [3]:
α = 25
β = 35
Out[3]:
In [4]:
α + β
Out[4]:
Se debe tener cuidado al asignar como variables las siguientes constantes matemáticas.
In [5]:
pi
Out[5]:
In [6]:
e
Out[6]:
In [7]:
eu
Out[7]:
In [8]:
catalan
Out[8]:
In [9]:
eulergamma
Out[9]:
In [10]:
golden
Out[10]:
In [11]:
x = 1
y = 2.0
u = 1 + 2im
v = 1.1 + 2.3im
a = true
b = "hola"
c = 'c'
d = "año"
println(typeof(x))
println(typeof(y))
println(typeof(u))
println(typeof(v))
println(typeof(a))
println(typeof(b))
println(typeof(c))
println(typeof(d))
También podemos usar números de precisión arbitraria:
In [12]:
factorial(12)
Out[12]:
In [13]:
factorial(13) # error por desbordamiento
In [14]:
x = big(13) # número de entero de precisión arbitraria
Out[14]:
In [15]:
typeof(x)
Out[15]:
In [16]:
factorial(x)
Out[16]:
In [17]:
y = big(12.2) # número de punto flotante de precisión arbitraria
Out[17]:
In [18]:
typeof(y)
Out[18]:
Recordemos que los números se representan en forma aproximada
In [19]:
1.1 + 0.1
Out[19]:
In [20]:
0.01 + 0.2
Out[20]:
Las operaciones aritméticas son binarias y existe precedencia de operadores
In [21]:
1 + 2
Out[21]:
In [22]:
1 - 2 + 3 # -1 + 3
Out[22]:
In [23]:
1/2
Out[23]:
In [24]:
1\2 # división inversa
Out[24]:
In [25]:
1//2 # número fraccional
Out[25]:
In [26]:
a = 1
b = 2
c = 3
Out[26]:
In [27]:
2a^2 + 4b + c
Out[27]:
In [28]:
2(a^2) + 4(b) + c
Out[28]:
In [29]:
1.2a^1.5 + 7.5b + c
Out[29]:
In [30]:
1.2(a^1.5) + 7.5(b) + c
Out[30]:
In [31]:
x = 1
Out[31]:
In [32]:
x = x + 3
Out[32]:
In [33]:
y = 1
Out[33]:
In [34]:
y -= 5
Out[34]:
In [35]:
1 == 1
Out[35]:
In [36]:
1.0 == 1
Out[36]:
In [37]:
1.1 > 1.2
Out[37]:
In [38]:
1.2 > 1.1
Out[38]:
In [39]:
1.2 == 1.2
Out[39]:
In [40]:
1 >= 1.0
Out[40]:
In [41]:
2 <= 3
Out[41]:
In [42]:
2 != 2
Out[42]:
En números de punto flotante existen +0 y -0
In [43]:
-0.0 == 0.0
Out[43]:
Si se quiere saber si son idénticos usar isequal()
In [44]:
isequal(-0.0, 0.0)
Out[44]:
In [45]:
isequal(1.0, 1)
Out[45]:
Valores especiales de numeros de punto flotante
In [46]:
1/0 # ∞
Out[46]:
In [47]:
-1/0 # -∞
Out[47]:
In [48]:
0/0 # indeterminado
Out[48]:
In [49]:
1 + Inf
Out[49]:
In [50]:
1 - Inf
Out[50]:
In [51]:
Inf + Inf
Out[51]:
In [52]:
Inf - Inf
Out[52]: