Abs: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
(abs) |
(No difference)
|
Revision as of 21:43, 21 October 2011
| Author: Lloigor (talk, contrib) |
Very simple macro to get the absolute value of an integer, without the math plugin.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Get Absolute value of an Integer ;; P1 :io: Integer ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; !define Abs "!insertmacro _Abs" !macro _Abs _Value_ IntCmp ${_Value_} -1 0 0 +2 ;; Is it negative? IntOp ${_Value_} ${_Value_} * -1 ;; Yes. Make it positive !macroend
Usage:
IntOp $IntVar 0 - 21 ; $IntVar = -21 ${ABS} $IntVar ; $IntVar = 21