Positron Compiler Documentation

fRound

Source: Positron8 Compiler User Manual, PDF page 103

Syntax

Assignment Variable = fRound(pVariable)

Overview

Round a value, variable or expression to the nearest integer.

Parameter

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

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
                             ' Holds the value to round
Dim Dwordout as Dword
                             ' Holds the result of fRound
Floatin = 1.9
                             ' Load the variable
Dwordout = fRound(Floatin)  ' Round to the nearest integer value
HRsoutLn Dec Dwordout
                             ' Display the integer result
Stop

Notes

Floating point trigonometry is extremely 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