May 2019
Beginner to intermediate
466 pages
10h 44m
English
Julia also provides a Rational number type. This allows us to work with exact ratios, instead of having to deal with the precision loss inherent in floats. Rational numbers are represented as their numerator and denominator values, separated by two forward slashes //:
julia> 3//2 3//2
Rational numbers can be converted to other types, if there is no data loss:
julia> 1//2 + 2//4 1//1 julia> Int(1//1) 1 julia> float(1//3) 0.3333333333333333 julia> Int(1//3) ERROR: InexactError: Int64(Int64, 1//3) julia> float(1//3) == 1/3 true
Read now
Unlock full access