aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorDrahflow <drahflow@gmx.de>2015-04-11 00:59:04 +0200
committerDrahflow <drahflow@gmx.de>2015-04-11 00:59:04 +0200
commit3e22eb797f02cdb54a5eccc8c6ebce33e1e1d7d5 (patch)
treea3683561e3ca0edc0e431a8aa142b86842db27a8 /doc
parentf0a883a15138991e09d4657b7d2aab491dafbc7b (diff)
Sane handling of integer division
Diffstat (limited to 'doc')
-rw-r--r--doc/global.md43
1 files changed, 41 insertions, 2 deletions
diff --git a/doc/global.md b/doc/global.md
index b6d74b1..8880d5d 100644
--- a/doc/global.md
+++ b/doc/global.md
@@ -593,12 +593,51 @@ Multiplies two integers or floats.
`div`
-----
-Divides two integers or floats. The integer version truncates the result towards zero.
+Divides two (signed) integers or floats. The integer version truncates the result towards zero.
5 2 div dump
0000000000000002
5 2 neg div dump
- FFFFFFFFFFFFFFFE
+ -0000000000000002
+
+
+`mod`
+-----
+
+Computes the remainder of a signed integer division. The result is always positive.
+
+ 5 2 mod dump
+ 0000000000000001
+ 5 neg 2 mod dump
+ 0000000000000001
+
+
+`udiv`
+-----
+
+Divides two unsigned integers. Truncates the result towards zero. Use this only
+if you need full 64bit unsigned integer arithmetic.
+
+ 5 2 udiv dump
+ 0000000000000002
+ 5 2 neg udiv dump
+ 0000000000000000
+ 5 neg 2 udiv dump
+ 7FFFFFFFFFFFFFFD
+
+
+`umod`
+-----
+
+Computes the remainder of an unsigned integer division. The result is always
+positive. Use this only if you need full 64bit unsigned integer arithmetic.
+
+ 5 2 umod dump
+ 0000000000000001
+ 5 neg 3 mod dump
+ 0000000000000001
+ 5 neg 3 umod dump
+ 0000000000000002
`and`