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 get JuliaLang version?
- How to use tuples in JuliaLang?
- How to test code in JuliaLang?
- How to install a package in JuliaLang?
- How to work with linear algebra in JuliaLang?
- How to calculate the mean in JuliaLang?
- How to create a histogram in JuliaLang?
- How to convert a string to an integer in JuliaLang?
- How to concatenate strings in JuliaLang?
- How to use the JuliaLang PackageCompiler?
See more codes...