Jump to content

sc_int vs sc_fixed behaviour


Recommended Posts

I found that sc_fixed's rounding behaviour is not consistent with my understanding. For example:


sc_fixed<10,10,SC_TRN,SC_WRAP> a;

sc_int<10> b;


I expect a and b should behave the same but if the values are -ve, their behaviours are not the same.


a = -75;  b = -75;


a = -(a>>6);  a becomes 1

b = -(b>>6);  b becomes 2


I would think b's behaviour is more correct because -75>>6 = -2 and -(-75>>6) = 2.


Anyone know why sc_fixed with q_mode=SC_TRN should not behave like sc_int?




Link to comment
Share on other sites

Hi Sam,


maybe this is strange but not a bug. 


The behavior you observe results from intermediate types. 

The intermediate result of a<<6 is not truncated, and results to -1.171875 or something like that. 

Then you invert this result and the truncation is done with the assignment. 


If you calculate in two steps (a=a<<6; a=-a;), the truncation is done after the shift and the result is 2.




Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...