Positron Compiler Documentation

dRound

Positron16 · Revision 1.1.3.5 · PDF page 111

Assignment Variable = dRound(pVariable)

Round a 64-bit floating point value, variable or expression to the nearest whole number.

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 DoubleIn as Double        ' Holds the value to round
Dim DwordOut as Dword           ' Holds the result of dRound

PPS_Output(cOut_Pin_RP14, cOut_Fn_U1TX)  ' Make Pin RB14 U1TX

DoubleIn = 1.9                  ' Load the variable
DwordOut = dRound(DoubleIn)    ' Round to the nearest whole value
HrsoutLn Dec DwordOut           ' Display the integer result (which is 2)
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 DoubleIn as Double        ' Holds the value to round
Dim DwordOut as Dword           ' Holds the result of dRound

PPS_Output(cOut_Pin_RP14, cOut_Fn_U1TX)  ' Make Pin RB14 U1TX

DoubleIn = 1.2                  ' Load the variable
DwordOut = dRound(DoubleIn)    ' Round to the nearest whole value
Hrsout Dec DwordOut, 13        ' Display the integer result (which is 1)

64-bit floating point routines are very memory hungry, so do not be surprised if a large chunk of the microcontroller’s code memory is used with a single operator. This also means that floating point trigonometry is comparatively slow to operate.

The compiler uses the stack as temporary storage when performing 64-bit floating point library routines, therefore, it may be required to increase the stack size from the default 120 words to 200 words using the Stack_Size declare. If the program resets with a stack underflow/overflow exception when running, the stack size is insufficient and requires increasing.

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