Add for rationals
This commit is contained in:
parent
75959a0fb3
commit
4dbb582311
1 changed files with 4 additions and 0 deletions
|
|
@ -28,6 +28,10 @@ proc `//`*[T](num, den: T): Rational[T] = initRational[T](num, den)
|
|||
## .. code-block:: nim
|
||||
## var x = 1//3 + 1//5
|
||||
|
||||
proc `$`*[T](x: Rational[T]): string =
|
||||
## Turn a rational number into a string.
|
||||
result = $x.num & "/" & $x.den
|
||||
|
||||
proc toRational*[T](x: SomeInteger): Rational[T] =
|
||||
## Convert some integer `x` to a rational number.
|
||||
result.num = x
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue