Positron Compiler Documentation

Modd

Positron16 · Revision 1.1.3.5 · PDF page 120

Assignment Variable = Modd (pVariable, pWhole)

Split a 64-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 64-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 MyDouble as Double
Dim fWhole as Double               ' Holds the whole part of the value
Dim fFraction as Double             ' Holds the fractional part of the value
Dim MyDword as Dword

RPOR7 = 3                           ' Make PPS Pin RP14 U1TX

MyDouble = 3.14

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

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