Positron Compiler Documentation

Abs

Positron8 · Revision 4.0.6.5 · PDF page 95

Assignment Variable = Abs(pVariable)

Return the absolute value of a constant, variable or expression.

pVariable can be a constant, variable or expression. Assignment Variable can be any valid variable type.

32-bit Example

Device = 18F26K40             ' Select the device to compile for
Declare Xtal = 16  ' Tell the compiler the device will be operating at 16MHz
Declare Hserial_Baud = 9600   ' Set the Baud rate for HRsoutLn

Dim DWordIn as Dword        ' Create an unsigned Dword variable
Dim DWordOut as Dword        ' Create an unsigned Dword variable

DWordIn = -1234567          ' Load DWordIn with value -1234567
DWordOut = Abs(DWordIn)      ' Extract the absolute value from DWordIn
HRsoutLn Dec DWordOut        ' Display the result, which is 1234567

Floating Point example

Device = 18F26K40             ' Select the device to compile for
Declare Xtal = 16  ' Tell the compiler the device will be operating at 16MHz
Declare Hserial_Baud = 9600   ' Set the Baud rate for HRsoutLn

Dim FloatIn as Float        ' Create a Floating Point variable
Dim FloatOut as Float        ' Create a Floating Point variable

FloatIn = -1234567          ' Load FloatIn with value -1234567
FloatOut = Abs(FloatIn)      ' Extract the absolute value from FloatIn
HRsoutLn Dec FloatOut        ' Display the result, which is 1234567

When implementing trigonometry, or other built in, functions within an expression, always wrap them in parenthesis, otherwise the parser may consider the extra operands as part of the trigonometry parameter and produce an incorrect result. For example:

MyAssignment = (Abs(MyVar1)) + MyVar2
View original PDF page 95Open page in PDFOriginal PDF page 95