summary refs log tree commit diff stats
path: root/tests/stdlib
diff options
context:
space:
mode:
authorshirleyquirk <31934565+shirleyquirk@users.noreply.github.com>2023-12-15 06:49:07 +0000
committerGitHub <noreply@github.com>2023-12-15 07:49:07 +0100
commita4628532b27857d095e69b7b162b453fc2b8373c (patch)
treea3a66ef302c373285d77069803f40f819cdfeb29 /tests/stdlib
parent94f7e9683fb5c9f643b7e4af367a3a6457d5ad7f (diff)
downloadNim-a4628532b27857d095e69b7b162b453fc2b8373c.tar.gz
rationals: support Rational[SomeUnsignedInt] (#23046)
fixes #22227
rationale:
    - `3u - 4u` is supported why not`3u.toRational - 4u.toRational`
- all of rationals' api is on SomeInteger, looks like unsigned is
declared as supported
  - math on unsigned rationals is meaningful and useful.
Diffstat (limited to 'tests/stdlib')
-rw-r--r--tests/stdlib/trationals.nim9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/stdlib/trationals.nim b/tests/stdlib/trationals.nim
index cd9954f61..22d7f5c2d 100644
--- a/tests/stdlib/trationals.nim
+++ b/tests/stdlib/trationals.nim
@@ -10,6 +10,7 @@ template main() =
     z = Rational[int](num: 0, den: 1)
     o = initRational(num = 1, den = 1)
     a = initRational(1, 2)
+    u = 3u // 2
     b = -1 // -2
     m1 = -1 // 1
     tt = 10 // 2
@@ -104,5 +105,13 @@ template main() =
   when sizeof(int) == 8:
     doAssert almostEqual(PI.toRational.toFloat, PI)
 
+  # unsigned
+  doAssert u == u
+  doAssert u + u == 3u // 1
+  doAssert 3u.toRational - u == u
+  doAssert u * 2 == 3u // 1
+
+
+
 static: main()
 main()