Positron Compiler Documentation

Abs

Positron16 · Revision 1.1.3.5 · PDF page 89

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 = 24FJ64GA002           ' Select the device to compile for
Declare Xtal = 16      ' Tell the compiler the device will be operating at 16MHz

Dim MyDword1 as Dword           ' Create an unsigned Dword variable
Dim MyDword2 as Dword           ' Create an unsigned Dword variable

MyDword1 = -1234567             ' Load MyDword1 with value -1234567
MyDword2 = Abs(MyDword1)       ' Extract the absolute value from MyDword1
HrsoutLn Dec MyDword2, 13      ' Display the result, which is 1234567

32-bit FloatIng Point example

Device = 24FJ64GA002           ' Select the device to compile for
Declare Xtal = 16      ' Tell the compiler the device will be operating at 16MHz

Dim MyFloat1 as Float           ' Create a Float variable
Dim MyFloat2 as Float           ' Create a Float variable

PPS_Output(cOut_Pin_RP14, cOut_Fn_U1TX)  ' Make Pin RB14 U1TX

MyFloat1 = -12345             ' Load MyFloat1 with value -12345
MyFloat2 = Abs(MyFloat1)       ' Extract the absolute value from MyFloat1
HrsoutLn Dec MyFloat2           ' Display the result, which is 12345

64-bit FloatIng Point example

Device = 24FJ64GA002           ' Select the device to compile for
Declare Xtal = 16      ' Tell the compiler the device will be operating at 16MHz

Declare Hserial_Baud = 9600    ' USART1 Baud rate
Declare Hrsout1_Pin = PORTB.14 ' Select the pin for TX with USART1

Dim MyDouble1 as Double        ' Create a Double variable
Dim MyDouble2 as Double        ' Create a Double variable

PPS_Output(cOut_Pin_RP14, cOut_Fn_U1TX)  ' Make Pin RB14 U1TX

MyDouble1 = -12345             ' Load MyDouble1 with value -12345
MyDouble2 = Abs(MyDouble1)      ' Extract the absolute value from MyDouble1
HrsoutLn Dec MyDouble2        ' Display the result, which is 12345

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)) + (ISin(MyVar2))
View original PDF page 89Open page in PDFOriginal PDF page 89