AnsweredAssumed Answered

Converting from float to fr16

Question asked by sauwen on Nov 10, 2010
Latest reply on Nov 16, 2010 by sauwen

Hello everybody,

 

I am trying to convert data from float to fr16, do some arithmetic with the fr16 and then convert back to float as a test.  I am using VisualDSP++5.0 with the Family Compiled Simulator. 

 

Here is my code:

 

#include <math.h>
#include <stdio.h>
#include <fract2float_conv.h>
#include <fract_typedef.h>
int main(void)
{
float floatnumber, floatnumber2, addedfrac16fl;
fract16 frac16number, frac16number2, addedfrac16fr;
floatnumber=0.001234;
floatnumber2=0.001234;
//convert to fr16
frac16number=float_to_fr16(floatnumber);
frac16number2=float_to_fr16(floatnumber2);
//addition test
addedfrac16fr=add_fr1x16(frac16number,frac16number2);
//convert to float
addedfrac16fl=fr16_to_float(addedfrac16fr);
printf("addedfrac16fl= %f\n", addedfrac16fl);
return 0;
}
Print statement shows: addedfrac16fl= 0.002441

 

Why is it that adding 0.001234+0.001234=0.002441??  Doesn't the datatype fr16 have enough significant digits so that there shouldn't be any error??  Or is the add_fr1x16 not doing what I think it is doing?

 

Thanks!!

Outcomes