Numbers and Math
This page provides syntax for using numbers and mathematic operations in Julia. Each section includes an example to demonstrate the described syntax and operations.
Types of Numbers
Integer (positive and negative counting number) - e.g., -3, -2, -1, 0, 1, 2, and 3
Signed:
Int8, Int16, Int32, Int64, and Int128Unsigned:
UInt8, UInt16, UInt32, UInt64, and UInt128Boolean:
Bool(0 = False and 1 = True)
Float (real or floating point numbers) - e.g.,
-2.14, 0.0, and 3.777Float16, Float32, Float64
Use typeof() function to determine type
Input:
# Define two variables x and y
x = 100
y = 3.14
# Print out the variable types for each
println(typeof(x))
println(typeof(y))Output:
Arithmetic Operators
Addition
x + y
Subtraction
x - y
Multiplication
x * y
Division
x / y
Power (Exponent)
x ^ y
Remainder (Modulo)
x % y
Negation (for Bool)
!x
Input:
Output:
Comparison Operators and Functions
Input:
Equality
x == y or isequal(x, y)
Inequality
x != y or !isequal (x, y)
Less than
x < y
Less than or equal to
x <= y
Greater than
x > y
Greater than or equal to
x >= y
Output:
Exercises
Create a Health Calculator Using Julia - Forthcoming!
Resources
Julia Documentation: Integers and Floating Point Numbers
Julia Documentation: Mathematical Operations and Elementary Functions
Julia Documentation: Numbers
Julia Documentation: Mathematics
Think Julia: Chapter 1 - The Way of the Program
Last updated
