Handmade Hero»Forums»Code
2 posts
Cannonical position vs double
Edited by co.nl.on on
On Day 32 and I must have missed this... is there a particular reason that Casey uses an int32+float for world coordinates instead of a double? I've checked the latest code and I see this is still the case.
Unless there's some performance/accuracy gain I don't understand, it strikes me as unnecessarily obtuse. Going from float to double adds 29 more bits to the mantissa, which is only 2 fewer bits than you get from an int32. Casey wants it to be possible to travel the Earth's circumference, is it so bad to restrict the player to only travelling 1/4 the Earth's circumference?
Gianluca Alloisio
33 posts
Cannonical position vs double
I think the reason is that all the calculations happens on the float, that is twice as fast as double. The int is updated only when the position changes block.
There could be a border case in which you'd have to count for the int and maybe re-base the floats, but I don't remember the actual code.
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
Cannonical position vs double
It's always a judgement call and it depends a lot on the target platform.

If we _do_ want to port to the original Raspberry Pi, for example, I don't believe it even _has_ double precision floating point, so you'd be running through software emulation if you used them!

However, since it's entirely possible that we won't do a port to the original Pi, since there is a newer Pi and might be another newer one still by the time we would consider porting, it's also likely that you could get away with doubles if you really want them.

My suspicion, and it's hard to say at this point, but my suspicion is that in the end, it will be pretty clear and easy to just store things in spatial bins anyway, so we never actually "need" an absolute position anyway.

- Casey