julialangHow to work with rational numbers in JuliaLang?
Rational numbers in JuliaLang can be represented using the Rational
type. For example, the fraction 1/2
can be represented as Rational{Int64}(1,2)
:
julia> Rational{Int64}(1,2)
1//2
To perform arithmetic operations on rational numbers, the //
operator can be used. For example, to add two rational numbers 1/2
and 1/3
:
julia> Rational{Int64}(1,2) + Rational{Int64}(1,3)
5//6
Code explanation
Rational
type: used to represent rational numbers//
operator: used to perform arithmetic operations on rational numbers
Helpful links
More of Julialang
- How to measure execution time in JuliaLang?
- How to test code in JuliaLang?
- How to create dataframes in JuliaLang?
- How to use tuples in JuliaLang?
- How to round numbers in JuliaLang?
- How to sort in JuliaLang?
- How to append to an array in JuliaLang?
- How to use the println function in JuliaLang?
- How to get JuliaLang version?
- How to create plots in JuliaLang?
See more codes...