Jump to content
samng

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?

 

Thanks,

Sam

Share this post


Link to post
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.

 

Greetings

Ralph

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×