6.1.0690 ABS abs CORE

( n -- u )

u is the absolute value of n.

Testing:

T{       0 ABS ->          0 }T
T{       1 ABS ->          1 }T
T{      -1 ABS ->          1 }T
T{ MIN-INT ABS -> MID-UINT+1 }T

ContributeContributions

BerndPaysanavatar of BerndPaysan [2] Reference implementationSuggested reference implementation2015-11-27 19:31:02

: ABS ( n -- +n ) DUP 0< IF NEGATE THEN ;

Reply New Version