My question is, how do know what value to multiply the floating point value to? I have a desktop application that shifts a float to 20 bits (n
- posted
15 years ago
My question is, how do know what value to multiply the floating point value to? I have a desktop application that shifts a float to 20 bits (n
Just look at the possible parameters to printf. Or sprintf.
--
First, I imagine that you can implement double precision with a DSP if you need to.
Choosing the scale factor for fixed point is a tradeoff between range, precision, and number of bits. Divide the maximum integer value by the maximum data value to get the maximum scale factor. From your values, if you want to represent them in a signed 16-bit value, the maximum scale factor is 32767/8.234526 = 3979.22. Scale factors are often a power of 2 or power of 10, but don't have to be. A scale factor of 2048 would suffice. With that scale factor, you have a resolution of 1/2048 = 0.000488, giving approximately 3 1/3 digits to the right of the decimal point. What type of quantity are you representing?
-- Thad
Depends on the least significant digit which needs to be accurate.
To represent 8.... you need as noted before 2048 as scale-factor (assuming shifting is the preferred way).
The boundary values will have an error below 1/1000 but what about the steps in between ?
I´d go for two 16bit registers, using 16bit fixed point (no shifting needed).
-- 42Bastian Do not email to bastian42@yahoo.com, it's a spam-only account :-)
They will also have an error below 1/2048.
The requirement for the extra precision depends on the application.
-- Thad
Probably 12. But it's impossible to be sure from the jumble of apparently unrelated pieces of information you supplied.
And maintaining excessive precision is meaningless if it exceeds the accuracy of the original data.
If the OP has data which is more accurate than about three decimal places (10 bits), then he's verging on the realm of high-accuracy instrumentation.
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.