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
Rationaltype: used to represent rational numbers//operator: used to perform arithmetic operations on rational numbers
Helpful links
More of Julialang
- How to test code in JuliaLang?
- How to use regular expressions in JuliaLang?
- How to round numbers in JuliaLang?
- How to add a legend to a plot in JuliaLang?
- How to solve differential equations in JuliaLang?
- How to append to an array in JuliaLang?
- How to install JuliaLang?
- How to use addprocs in JuliaLang?
- How to install JuliaLang on Ubuntu?
- How to create dataframes in JuliaLang?
See more codes...