hlslibs/ac_types

Division for signed ac_fixed could get incorrect result

Closed this issue · 2 comments

Below is an example to show the division difference between signed ac_fixed and double:

#include "ac_types/include/ac_fixed.h"

int main()
{
    ac_fixed<40,30,true> num = -46800;
    ac_fixed<40,30,true> den = 2136;
    ac_fixed<40,30,true> q = num / den;

    std::cout << "division using ac_fixed division = " << q.to_string(AC_BIN) << ", " << q << std::endl;

    q = static_cast<double>(num.to_int64())/den.to_int64();

    std::cout << "division using double   = " << q.to_string(AC_BIN) << ", " << q << std::endl;

   return 0;
}

The output of the above code snippet.

division using ac_fixed = 0b101010.0001011101, -21.9091796875
division using double   = 0b101010.0001011100, -21.91015625

Ah, thanks for the documentation details. That explains.