causative Posted May 2, 2016 Share Posted May 2, 2016 (edited) The actual data for a fixed object is an i32, right? So why not have "typedef i32 fixed" and instead of using a CFixed class, just have utility functions for operating on i32 as fixed-precision numbers. Edited May 2, 2016 by causative Link to comment Share on other sites More sharing options...
sanderd17 Posted May 2, 2016 Share Posted May 2, 2016 Because operations don't work. F.e. take multiplication. Take (as a small example, I won't write out 32 bits) it's stored in 8 bits, of which 1 bit is for the sign 4 are for the integer value, and 3 for the decimal places. Then 1 is represented as 1000 in binary, so 1*1 integer multiplication is 1000000 = 16. Doesn't really work out eh? The functions made available in CFixed make sure the numbers get shifted to one side or the other so these operations do make sense (and take into account unexpected overflows). It's just easier when you can do a*b with fixed numbers, and let it give the correct result. Instead of calling some method mult() defined in an obscure place. 1 Link to comment Share on other sites More sharing options...
causative Posted May 2, 2016 Author Share Posted May 2, 2016 Right, plus an instance of fixed is the same size as an i32, so there wouldn't be any performance benefit. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now