causative Posted May 2, 2016 Report 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 Quote Link to comment Share on other sites More sharing options...
sanderd17 Posted May 2, 2016 Report 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 Quote Link to comment Share on other sites More sharing options...
causative Posted May 2, 2016 Author Report 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. 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.