samng Posted July 5, 2013 Report Share Posted July 5, 2013 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 Quote Link to comment Share on other sites More sharing options...
ralph.goergen Posted July 5, 2013 Report Share Posted July 5, 2013 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 Quote Link to comment Share on other sites More sharing options...
samng Posted July 5, 2013 Author Report Share Posted July 5, 2013 Hi Ralph, Thank you for the explanation. Any idea what is the intermediate type? Some kind of floating point type? Thanks, Sam Quote Link to comment Share on other sites More sharing options...
ralph.goergen Posted July 8, 2013 Report Share Posted July 8, 2013 The return type of the << operator is sc_fxval, as far as i know. 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.