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 test code in JuliaLang?
- How to work with matrices in JuliaLang?
- How to use the println function in JuliaLang?
- How to install JuliaLang on Ubuntu?
- How to use the JuliaLang PackageCompiler?
- How to create a package in JuliaLang?
- How to use try catch in JuliaLang?
- How to use regular expressions in JuliaLang?
- How to use enums in JuliaLang?
See more codes...