Skip to content
  • Home
  • Account
  • Restricted content
  • OBEX
  • Chips Tips
  • Logout
  • Shop
  • QuickBytes
Propeller OBEX
  • OBEX
  • Forum
Login
Propeller OBEX

Propeller 2

  • Configuring Visual Studio Code for Programming the P2 on Mac, Windows, and Linux
  • Breakout Board Options for P2 Edge Modules
  • Solar Panel Monitoring Demo (Intro to Using Video 3 of 3)
  • Wireless Programming with the ESP8266 WX Module
  • Brushless DC Motor Control Demo
  • Colorful Terminal Output with ANSI Escape Sequences
  • XBee RF Transparent and API Mode Demo
  • DS3231 Real Time Clock I2C Demo
  • Multiple Servo Control (up to 64) Object
  • Multiple Serial Port (8 UART – 16 Tx/Rx) Object
  • Goertzel Operation with Ultrasonic Transducers
  • Web Page Control of WS2811 LEDs Using the IoT Gateway on Raspberry Pi
  • 320×240 LCD Driver for ILI9341 Controller and XPT2046 Touch Screen
  • Digital Sample ADC to DAC + Analog Frequency to DAC
  • Using Smart Pins to Measure Frequency Output of TSL235R Light-to-Frequency Sensor
  • Ping))) Ultrasonic Distance Sensor with Graphical Debug Demo
  • Simple Analog Input
  • P2 Edge 16 MB Flash Reader and Explorer Utility
  • LED Matrix used as an I/O Test Utility
  • Arlo Conversion to P2 with the Universal Motor Controller
  • Five Buttons On One Pin
  • P2 RTC Add-on Board Demo
  • Simple Video Driver – Using Images (Intro to Using Video 2 of 3)
  • Starting Your P2 Project with a Spin2 Template
  • E-Ink Display Demo
  • MAX7219 LED Display SPI Demo
  • DHT11, DHT22, CM2302 Humidity and Temperature Sensor Object
  • NMEA GPS String Parsing
  • Floating Point Math: DEBUG and Terminal Display Example
  • LEDs – Beyond the Basics
  • Quadrature Encoder Object
  • P2 RTC Add-on with GPS Module
  • DVI/VGA Text Driver Demo
  • PCF8574 I2C LCD Demo
  • Simple Sound Engine Demo
  • 1-Wire Driver with DS18B20 Temperature Sensor Demo
  • Send Email from the Propeller 2 Using the IoT Gateway on Raspberry Pi
  • I2C Device Bus Scanner Utility
  • 32-Channel ADC Object
  • Tetris
  • Video Hardware with Character Map Demo (Intro to Using Video 1 of 3)
  • WS2811, WS2812, WS2812b, WS2813, SK6812x NeoPixel Object
View Categories
  • Home
  • Docs
  • Quick Bytes
  • Propeller 2
  • Floating Point Math: DEBUG and Terminal Display Example

Floating Point Math: DEBUG and Terminal Display Example

Reading Time: 2 min read

Description #

Run-time floating-point operators have recently been added to Spin2’s language interpreter. These operators utilize the 32-bit IEEE-754 floating-point format. Parallax’s Propeller Tool (ver 2.6.2 and higher) and FlexProp (ver. 5.9.6 and higher) support the use of floating-point math. The largest possible floating-point number that can be used is 3.4e+38.

Floating-point variables in Spin2 are really just LONG variables, but they get treated as floats when the special floating-point operators are used on them. The floating-point operators have the same precedence as the normal integer operators and often use the same symbol, but with a period after each:

-. value        = negate
FABS value      = absolute
value *. value  = multiply
value /. value  = divide
value +. value  = add
value -. value  = negate
value <. value  = check for less-than, returns integer 0 or -1
value <=. value = check for less-than-or-equal, returns integer 0 or -1
value ==. value = check for equal, returns integer 0 or -1
value <>. value = check for not-equal, returns integer 0 or -1
value >=. value = check for greater-than-or-equal, returns integer 0 or -1
value >. value  = check for greater-than, returns integer 0 or -1
value <. value  = check for less-than, returns integer 0 or -1
FLOAT(integer)  = convert integer to float
ROUND(float)    = round float to integer
TRUNC(float)    = truncate float to integer
NAN(float)      = check float for not-a-number, returns integer 0 or -1

Floating-point constants must either have a decimal point and/or and “e” in them:

1.0
-. 5.0 remember to always use the floating-point negate
1e6
1e-9 "e" can be followed by "-", "+", or just a number
6.02e+23
6.02e23

Floating-point values may be displayed using these functions:

FDEC(value)
FDEC_ARRAY(hub_pointer, size)
FDEC_REG_ARRAY(reg_pointer, size)

Example #1: Propeller Tool for Windows Using DEBUG 

The most simple and direct way of displaying a floating-point number is using Propeller Tool for Windows with the new DEBUG statement, as shown in this example. The output from the program is included below, for reference. 

' Floating Point Example Using Propeller Tool Debug

CON
  _clkfreq      = 10_000_000

PUB go()| radius, area

  radius := 6.2             ' 6.2 radius circle
  area := (PI *. (radius *. radius))
  debug(FDEC(area))

When the DEBUG command is used, the serial port is held by the DEBUG Output window and you will not be able to use Parallax Serial Terminal.

Example #2: Propeller Tool for Windows Using Parallax Serial Terminal

Parallax Serial Terminal may be used to display a floating-point number using a method in jm_fullduplexserial.spin2. If X is the number of digits you would like to display after the decimal point, multiply your floating-point value by 10.0^X and then convert it to a fixed point for display using %f in a formatted print statement. Alternatively, the dpdec() method may also show the value right of the decimal point. 

The relevant lines of code are highlighted below (and note that the debug statements are removed).

' Floating Point Example Using PST or ANSI Terminal

CON
  _clkfreq      = 10_000_000
  BR_TERM  = 230_400                                            
  #0, T_PST, T_ANSI                                             
  T_TYPE = T_PST

obj
  term   : "jm_fullduplexserial"                          
  ansi   : "jm_ansi"                                              

PUB go()| i, radius, area

  term.tstart(BR_TERM)                                          
  wait_for_terminal(true)

'' Area = PI*R*R example
  radius := 6.2             ' 6.2 radius circle
  area := (PI *. (radius *. radius))
  area := round(area *. 1000000.0)
  term.fstr1(string("Area = %.6f\r"), area)
 
pub wait_for_terminal(clear)

'' Wait for terminal to be open and key pressed

  term.rxflush()
  term.rx()
  if (clear)
    clear_screen()

pub clear_screen()

  if (T_TYPE == T_PST)
    term.tx(term.CLS)
  else
    term.str(ansi.hide_cursor())
    term.str(ansi.home())
    term.str(ansi.cls())

Example #3: FlexProp and ANSI Terminal

Eric Smith’s FlexProp may be used the same way as Propeller Tool, with the additional benefits of Mac and Linux. To use Terminal with FlexProp, change the T_TYPE to T_ANSI and compile. 

To use the DEBUG commands in FlexProp, go to Options | BRK Debug. 

Parts Used #
  • P2 Edge Module
  • P2 Edge Breadboard
Source Code #
  • Floating Point Example for PST and FlexProp Terminal
  • DEBUG Example for Propeller Tool and FlexProp
Programming Language #
  • Spin 2
Tools and Operating System #
  • Propeller Tool for Windows
  • FlexProp for Windows, Mac and Linux
Additional Resources #
  • Graphical Debug Tools in Spin2
Document Author #
  • Ken Gracey
Source Code Author #
  • Ken Gracey, Jon McPhalen
Was this useful ?

Share This Article :

  • Facebook
  • X
  • LinkedIn
Still stuck? How can we help?

Still stuck? How can we help?

Updated on September 29, 2026
NMEA GPS String ParsingLEDs – Beyond the Basics
Table of Contents
  • Description
  • Parts Used
  • Source Code
  • Programming Language
  • Tools and Operating System
  • Additional Resources
  • Document Author
  • Source Code Author

Copyright © 2026 - Parallax Inc.
599 Menlo Drive | Rocklin, CA 95765 | USA