Source
Edit
For template `/=`*(x: var SomeInteger, y: SomeInteger):
Nim is static-typed, but /= will cause lhs convert from int to float
func `%`[T: SomeNumber](a, b: T): T
-
Python's modulo (a.k.a floor modulo) (quotient)
Hint:
Nim's mod is the same as a - b * (a div b) (remainder), just like C.
Example:
assert 13 % -3 == -2
assert -13 % 3 == 2
Source
Edit
func `//`[A, B: SomeFloat | SomeInteger](a: A; b: B): SomeNumber {.inline.}
-
Python's division (a.k.a. floor division)
Hint:
Nim's div is division with any fractional part discarded (a.k.a."truncation toward zero"), just like C.
Example:
assert 13 // -3 == -5
assert 13 div -3 == -4
Source
Edit
func divmod[T: SomeNumber](x, y: T): (T, T)
-
differs from std/math divmod, see // and % for details.
Source
Edit
template `%`[A: SomeFloat; B: SomeInteger](a: A; b: B): A
-
Source
Edit
template `%`[A: SomeInteger; B: SomeFloat](a: A; b: B): B
-
Source
Edit
template `**`[A: SomeFloat; B: SomeInteger](a: A; b: B): A
-
Source
Edit
template `**`[A: SomeInteger; B: SomeFloat](a: A; b: B): B
-
Source
Edit
template `**`[T: SomeInteger](a: T; b: static[int]): int | float
-
power for static int b
so that result type can be inferred:
- int if b >= 0
- float if b < 0
For non-static int b, `**`(a: T; b: Natural) is used.
Example:
const f = 5 ** -1
assert f == 0.2
const i = 5 ** 2
assert i == int(25)
Source
Edit
template `**`[T](a: T; b: Natural): T
-
power for b is a non-static integer:
only Natural is acceptable unless b is static, see `**`(a: T; b: static[int])
Example:
var i = -1
doAssertRaises RangeDefect:
discard (5 ** i)
Source
Edit
template `<`[A: SomeFloat; B: SomeInteger](a: A; b: B): bool
-
Source
Edit
template `<`[A: SomeInteger; B: SomeFloat](a: A; b: B): bool
-
Source
Edit
template `<<`[I: SomeInteger](a, b: I): I
-
Warning:
this causes overflow silently. Yet Python's int never overflows.
Source
Edit
template `<=`[A: SomeFloat; B: SomeInteger](a: A; b: B): bool
-
Source
Edit
template `<=`[A: SomeInteger; B: SomeFloat](a: A; b: B): bool
-
Source
Edit
template `<>`[A: SomeFloat; B: SomeInteger](a: A; b: B): bool
-
Source
Edit
template `<>`[A: SomeInteger; B: SomeFloat](a: A; b: B): bool
-
Source
Edit
template `==`(a, b: typedesc): bool
-
Compare 2 typedesc like Python.
Example:
doAssert type(1) == type(2)
Source
Edit
template `==`[A: SomeFloat; B: SomeInteger](a: A; b: B): bool
-
Source
Edit
template `==`[A: SomeInteger; B: SomeFloat](a: A; b: B): bool
-
Source
Edit