summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorJamesP <jlp765@gmail.com>2015-10-01 15:07:23 +1000
committerJamesP <jlp765@gmail.com>2015-10-01 15:07:23 +1000
commit2f4cc4efce714f036018107f73cf1f5db40cbffd (patch)
tree8e50a02a4a9ed8359ffeeb20fdbdfc3644ce8d8e /lib
parentd6b7f0ad9e7a07cdd8295083e1c737a7bf0c6305 (diff)
downloadNim-2f4cc4efce714f036018107f73cf1f5db40cbffd.tar.gz
add a few type checks to limit type to SomeInteger
(adding a compund type to the Rational type definition
made it too difficult to define new variables
using integer literals)
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/rationals.nim6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/pure/rationals.nim b/lib/pure/rationals.nim
index 79dc6de16..7d9241412 100644
--- a/lib/pure/rationals.nim
+++ b/lib/pure/rationals.nim
@@ -18,7 +18,7 @@ type Rational*[T] = object
   ## a rational number, consisting of a numerator and denominator
   num*, den*: T
 
-proc initRational*[T](num, den: T): Rational[T] =
+proc initRational*[T:SomeInteger](num, den: T): Rational[T] =
   ## Create a new rational number.
   assert(den != 0, "a denominator of zero value is invalid")
   result.num = num
@@ -34,7 +34,7 @@ proc `$`*[T](x: Rational[T]): string =
   ## Turn a rational number into a string.
   result = $x.num & "/" & $x.den
 
-proc toRational*[T](x: T): Rational[T] =
+proc toRational*[T:SomeInteger](x: T): Rational[T] =
   ## Convert some integer `x` to a rational number.
   result.num = x
   result.den = 1
@@ -48,7 +48,7 @@ proc toInt*[T](x: Rational[T]): int =
   ## `x` does not contain an integer value.
   x.num div x.den
 
-proc reduce*[T](x: var Rational[T]) =
+proc reduce*[T:SomeInteger](x: var Rational[T]) =
   ## Reduce rational `x`.
   let common = gcd(x.num, x.den)
   if x.den > 0: