Positron Compiler Documentation

fAbs

Positron16 · Revision 1.1.3.5 · PDF page 90

Assignment Variable = fAbs(pVariable)

Return the absolute value of a constant, variable or expression as 32-bit floating point.

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

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 MyFloat as Float           ' Create a Float variable
Dim FloatOut as Float           ' Create a Float variable

PPS_Output(cOut_Pin_RP14, cOut_Fn_U1TX)  ' Make Pin RB14 U1TX

MyFloat = -3.14                ' Load MyFloat with value -3.14
FloatOut = fAbs(MyFloat)       ' Extract the absolute value from MyFloat
HrsoutLn Dec FloatOut           ' Display the result, which is 3.14

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 = (fAbs(MyVar1)) + (Sin(MyVar2))
View original PDF page 90Open page in PDFOriginal PDF page 90