There may be several interpretations in your question.
If it's just for corners and for storage on disk or on a device, I suggest you store your values ββusing a completely different technique: store as a 32-bit integer.
int encodedAngle = (int)(value * (0x7FFFFFFF / 180.0));
To restore it, do the opposite.
double angle = (encodedAngle / (0x7FFFFFFF / 180.0));
So you have full 31-bit resolution for 180 degrees and 1 bit for sign.
You can use this method to save your values ββin ram, the cost of this coversion is higher than working directly with doubling, but if you want your memory to be low but with high resolution, this can work very well. The cost is not so high, just converting to / from an integer from / to double and multiplying, modern processors will do this in a very short time, and since the available memory is less, if the list contains a lot of value, your code will be more friendly with the processor cache .
Your resolution will be 180 / ((2^31) - 1) = 8.38190318 Γ 10^-8 degrees, not bad :)
Salvatore previti
source share