Positron Compiler Documentation

Modf

Positron16 · Revision 1.1.3.5 · PDF page 119

Assignment Variable = Modf (pVariable, pWhole)

Split a 32-bit floating point value into fractional and whole parts.

pVariable can be a floating point constant, variable or expression that will be split. pWhole must be a 32-bit floating point variable that will hold the whole part of the split value. 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
Dim fWhole as Float                  ' Holds the whole part of the value
Dim fFraction as Float             ' Holds the fractional part of the value
Dim MyDword as Dword

RPOR7 = 3                           ' Make PPS Pin RP14 U1TX
MyFloat = 3.14

fFraction = Modf(MyFloat, fWhole)   ' Split the value
MyDword = fWhole                    ' Convert the whole part to an integer
HrsoutLn "Whole = ", Dec MyDword
HrsoutLn "Fraction = ", Dec fFraction

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