Patrick Posted January 7, 2020 Report Share Posted January 7, 2020 Hi, while implementing a project I noticed that my calculations using sc_dt::sc_ufix won't get more accurate when increasing the fractional bit width. As you can see in the following example I'm increasing the number of fractional bits and calculate 1/3: #include <iostream> #include <iomanip> #include <systemc.h> int sc_main(int argc, char *argv[]) { { int i = 9; do { sc_fxtype_context evalContext(sc_fxtype_params(i, 8)); sc_dt::sc_ufix a = 1; sc_dt::sc_ufix b = 3; sc_dt::sc_ufix r = a / b; std::cout << std::setw(3) << std::setfill('0') << i - 8; std::cout << " | " << r << " | " << r.to_bin() << std::endl; i++; } while (i < 120); } return (0); } While the results look as expected at first, they won't change any more after the 64th fractional bit (output.txt). Why is this happening? I can use fractional bits >= 64 (e.g. by shifting to the right), but my calculations don't use them. None of them uses any bits beyond the 64th, thus increasing the fractional accuracy has no effect. Searching in the standard I wasn't able to find a restriction for calculations with finite-precision fixed-point numbers, only for different types (limited-precision fixed-point calculations like sc_dt::sc_ufix_fast for example should not exceed 53 bits). Quote Link to comment Share on other sites More sharing options...
Timur Kelin Posted January 8, 2020 Report Share Posted January 8, 2020 Hi Patrick you can compile with -DSC_FXDIV_WL=128 to increase max precision of the div operation 100 | .3333333333333333333333333333330703796982596627315294238115724045901089311882969923317432403564453125 | 0b000000000.0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101 101 | .3333333333333333333333333333330703796982596627315294238115724045901089311882969923317432403564453125 | 0b000000000.01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010 102 | .333333333333333333333333333333267594924564915682882355952893101147527232797074248082935810089111328125 | 0b000000000.010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101 103 | .333333333333333333333333333333267594924564915682882355952893101147527232797074248082935810089111328125 | 0b000000000.0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010 104 | .33333333333333333333333333333331689873114122892072058898822327528688180819926856202073395252227783203125 | 0b000000000.01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101 105 | .33333333333333333333333333333331689873114122892072058898822327528688180819926856202073395252227783203125 | 0b000000000.010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010 106 | .3333333333333333333333333333333292246827853072301801472470558188217204520498171405051834881305694580078125 | 0b000000000.0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101 107 | .3333333333333333333333333333333292246827853072301801472470558188217204520498171405051834881305694580078125 | 0b000000000.01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010 108 | .333333333333333333333333333333332306170696326807545036811763954705430113012454285126295872032642364501953125 | 0b000000000.010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101 109 | .333333333333333333333333333333332306170696326807545036811763954705430113012454285126295872032642364501953125 | 0b000000000.0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010 110 | .33333333333333333333333333333333307654267408170188625920294098867635752825311357128157396800816059112548828125 | 0b000000000.01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101 111 | .33333333333333333333333333333333307654267408170188625920294098867635752825311357128157396800816059112548828125 | 0b000000000.010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.