Introduction #
SPIN2 introduces native 32-bit floating point support for the Propeller 2. The implementation follows IEEE-754 encoding rules, with a bit sequence comprising a sign bit, followed by exponent and then mantissa (significand) bits.
An interesting tool to experiment with the float bit pattern can be found in resources!
Specifications #
Sign Exponent Mantissa (IEEE-754 encoding) | S_EEEEEEEE_MMMMMMMMMMMMMMMMMMMMMMM |
Largest supported floating point value | 3.4e+38 |
Methods #
Floating-point conversion methods
FLOAT(x)
TRUNC(x)
ROUND(x)
NAN(x) ' Note: run-time only
Operators #
Most SPIN2 floating point operators use the same structure as the corresponding integer based operators, with the addition of a dot character to inform the compiler that float point handling is required.
Floating-point relational operators
<.
>.
<>.
==.
<=.
>=.
Floating-point unary operators
-.
FABS(x)
FSQRT(x)
Floating-point binary operators
+.
-.
*.
/.
Code Snippet #
This example will open a debug terminal window and display the float point results. Copy this code into PNUT, Propeller Tool or SPIN Tools IDE and load it with the DEBUG option enabled to your connected P2
CON
_clkfreq = 10_000_000
PUB go(): i
i := 3.4e+38 ' biggest floating-point number possible
repeat 85 ' keep dividing it by 10.0 until it's zero
debug(fdec(i), uhex_long(i))
i := i /. 10.0
Resources #
Parallax Propeller 2 - Spin2 Language Documentation
Float Bit Pattern - Online Tool