Positron Compiler Documentation

fRound

Source: Positron16 Compiler User Manual, PDF page 110

Syntax

Assignment Variable = fRound(pVariable)

Overview

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

Parameter

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

Example 1

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 FloatIn as Float
                                ' Holds the value to round
Dim DwordOut as Dword
                                ' Holds the result of fRound
PPS_Output(cOut_Pin_RP14, cOut_Fn_U1TX)  ' Make Pin RB14 U1TX
FloatIn = 1.9
                                ' Load the variable
DwordOut = fRound(FloatIn)
                                ' Round to the nearest whole value
HrsoutLn Dec DwordOut
                                ' Display the integer result (which is 2)

Example 2

Device = 24FJ64GA002
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 FloatIn as Float
                                ' Holds the value to round
Dim DwordOut as Dword
                                ' Holds the result of fRound
RPOR7 = 3
                                ' Make PPS Pin RP14 U1TX
FloatIn = 1.2
                                ' Load the variable
DwordOut = fRound(FloatIn)
                                ' Round to the nearest whole value
HrsoutLn Dec DwordOut
                                ' Display the integer result (which is 1)

Notes.

FloatIng point routines are rather 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.

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 = (fRound(MyVar1)) + MyVar2