Positron Compiler Documentation

Log

Positron16 · Revision 1.1.3.5 · PDF page 115

Assignment Variable = Log(pVariable)

Deduce the Natural Logarithm a 32-bit floating point value

pVariable can be a constant, variable or expression that requires the natural logarithm extracted. 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 FloatIn as Float           ' Holds the value to Log with
Dim FloatOut as Float           ' Holds the result of the Log

RPOR7 = 3                       ' Make PPS Pin RP14 U1TX

FloatIn = 1                    ' Load the variable
FloatOut = Log(FloatIn)        ' Extract the Log of the value
HrsoutLn Dec FloatOut           ' Display the result

FloatIng point trigonometry is 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 = (Log(MyVar1)) + MyVar2
View original PDF page 115Open page in PDFOriginal PDF page 115