Represent datatype with given resolution

I would like to represent a given datatype in my C++ code. (A measurement signal with given resolution)

The input real measurement signal can represent values from 3e-10 to 65000 (approximations). All numbers between +/- 3.5e-10 are truncated to 0.
'Units in the Last Place' is 1.5e-5.

How can I write a method to "round off" my numbers not to have better prececision than this? (I think is ok to do this once in the method that receives the numbers..

my_calc(float inputNum)
{
float correctPrec = scaleInputToCorrectPresision(inputNum);
//some calculations with inputNum
}
1
2
3
4
if(inputNum < 3.5e-10 && inputNum > -3.5e-10)
{
inputNum = 0;
}

??
Yes, that is ok to truncate the minimum value. But how do I get the precision?
The precision should not better than 1.5e-5..

The measurement is defined as:
+/- significant*2^exp, there
significant is 16 bit, representing values 1 to 1.99998
exp is 5 bit representing -15 to 15.

(This gives min value as 2^-15 and max value as 1.99*2^15..
You could use a library that provides fixed point decimal numbers support

For Texas Instruments DSPs for example, IQMath lib represents them on integers, they provide 32 subtypes depending on how you many bits you want to represnt the integral and the decimal part. In your case for example, you could use the type unsigned IQ16 that has :
16 bits for the decimal part -> 1/65536 = 1.5e-5 of precision of representation
16 bits for the integral part -> 0-> 65535 if it is unsigned
Last edited on
Topic archived. No new replies allowed.