Floating point class with 3 digits accuracy
Peter Verkaik
Posts: 3,956
Hi,
I uploaded a floating point class with 3 digits accuracy here:
http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/math/
classes f3.java and f3_test.java
·* This class provides floating point math routines, limited to 3 digits accuracy.
·* A floating point value is stored in an integer (16 bits), to keep the code minimal.
·* This should fill the gap between fixed point arithmatic (very limited range) and
·* the true floating point class Float32 (huge code).
·*
·* f3 value floating point format
·*
·*···· +-+
+-+----+
·*···· |s|mmmmmmmmmm|x|eeee|
·*···· +-+
+-+----+
·*
·*···· s = mantissa sign (1 bit)
·*···· m = mantissa····· (10 bits)
·*···· x = exponent sign (1 bit)
·*···· e = exponent····· (4 bits)
·*
·* The signed range is from -0.999E+15 to +0.999E+15 which should be sufficient.
·* Near zero, the smallest values are -0.001E-16 and +0.001E-16 which also should
·*·be sufficient.
·* The f3 value zero 0.000E+00 equals the integer value zero (binary null).
·*
·* Given the fact, that if a measured value has a 3 digit accuracy (like ADC values),
·* any result calculated with that value can never have more significant digits, the 3 digit
·* accuracy of a f3 value may be accurate enough for those cases. If it isn't, use the
·* Float32 package or a co-processor like the uM-FPU.
·*
Here are the results of the test program
Class f3 test program
add:· a= 0.314E+01·· b= 0.272E+01·· c= 0.586E+01
sub:· a= 0.314E+01·· b= 0.272E+01·· c= 0.420E+00
mul:· a= 0.314E+01·· b= 0.272E+01·· c= 0.854E+01
div:· a= 0.314E+01·· b= 0.272E+01·· c= 0.115E+01
Program finished
regards peter
Post Edited (Peter Verkaik) : 1/4/2006 6:29:15 PM GMT
I uploaded a floating point class with 3 digits accuracy here:
http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/math/
classes f3.java and f3_test.java
·* This class provides floating point math routines, limited to 3 digits accuracy.
·* A floating point value is stored in an integer (16 bits), to keep the code minimal.
·* This should fill the gap between fixed point arithmatic (very limited range) and
·* the true floating point class Float32 (huge code).
·*
·* f3 value floating point format
·*
·*···· +-+
+-+----+
·*···· |s|mmmmmmmmmm|x|eeee|
·*···· +-+
+-+----+
·*
·*···· s = mantissa sign (1 bit)
·*···· m = mantissa····· (10 bits)
·*···· x = exponent sign (1 bit)
·*···· e = exponent····· (4 bits)
·*
·* The signed range is from -0.999E+15 to +0.999E+15 which should be sufficient.
·* Near zero, the smallest values are -0.001E-16 and +0.001E-16 which also should
·*·be sufficient.
·* The f3 value zero 0.000E+00 equals the integer value zero (binary null).
·*
·* Given the fact, that if a measured value has a 3 digit accuracy (like ADC values),
·* any result calculated with that value can never have more significant digits, the 3 digit
·* accuracy of a f3 value may be accurate enough for those cases. If it isn't, use the
·* Float32 package or a co-processor like the uM-FPU.
·*
Here are the results of the test program
Class f3 test program
add:· a= 0.314E+01·· b= 0.272E+01·· c= 0.586E+01
sub:· a= 0.314E+01·· b= 0.272E+01·· c= 0.420E+00
mul:· a= 0.314E+01·· b= 0.272E+01·· c= 0.854E+01
div:· a= 0.314E+01·· b= 0.272E+01·· c= 0.115E+01
Program finished
regards peter
Post Edited (Peter Verkaik) : 1/4/2006 6:29:15 PM GMT
Comments
Thank you for posting this.
Ryan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ryan Clarke
Parallax Tech Support
RClarke@Parallax.com