This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

round result of floating point calcualtion

Hello,

I have a problem with the accuracy of the result when I divide 2 float values.

This is the line in my source Code:

 dds_word.long_dds = 2.147483648E16 / 7.1312E7 

The result which I get is 3.011392E8

The unrounded result is 3.0113916845E8

There is no difference when I work with float or double variables. Is there any possibility to get more accuracy?

Parents
  • I have solved the problem.
    Here is the solution which I use. I hope I will get no problem with the timing.


    
    unsigned long test_value;
    unsigned int result;
    unsigned long test_freq;
    
    
             dds_word.long_dds = 0;
             test_value = 0x04C4B400;
             for (i=0; i<7; i++)
                {
                result = test_value / test_freq;
                test_value = test_value - (result * test_freq);
                test_value = test_value << 4;
                dds_word.long_dds += result;
                dds_word.long_dds = dds_word.long_dds << 4;
                }
             result = test_value / test_freq;
             dds_word.long_dds += result;
    
    
    

    Thx at all for help.

    Jan

Reply
  • I have solved the problem.
    Here is the solution which I use. I hope I will get no problem with the timing.


    
    unsigned long test_value;
    unsigned int result;
    unsigned long test_freq;
    
    
             dds_word.long_dds = 0;
             test_value = 0x04C4B400;
             for (i=0; i<7; i++)
                {
                result = test_value / test_freq;
                test_value = test_value - (result * test_freq);
                test_value = test_value << 4;
                dds_word.long_dds += result;
                dds_word.long_dds = dds_word.long_dds << 4;
                }
             result = test_value / test_freq;
             dds_word.long_dds += result;
    
    
    

    Thx at all for help.

    Jan

Children
No data