From 3e22eb797f02cdb54a5eccc8c6ebce33e1e1d7d5 Mon Sep 17 00:00:00 2001 From: Drahflow Date: Sat, 11 Apr 2015 00:59:04 +0200 Subject: Sane handling of integer division --- doc/global.md | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'doc') 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` -- cgit v1.2.3