Presumably he meant they were using the high bytes of the double for one integer and the low bytes for another, not storing string representations (which wouldn't fit in a double anyway). So the top 4 bytes of a 64bit double would store 0 as a 32bit int, and the lower 4 bytes would store 10 as another 32bit int, and there'd be no issue differentiating between 1, 10 and 100.
Still a bit pointless unless the system they're using doesn't have a compiler with things like uint32 defined, but that might actually be the case for some architectures.
If he's reading it right and it really is storing the values on sides of the decimal that is extra bizarre, since doubles are floating point. I don't think anyone would jump through the hoops needed to try to make that work, so yeah he's either making it up or misreading.
Anyway, it's not like shitty devs don't exist all over, op would find other retardedness outside of embedded. The int inside doubles thing might be justified though (actually if the c compiler is homebrewed for some obscure chip, even the code in header files might be justified). Given that OP has two weeks of experience, he probably doesn't understand what is going on enough to judge what really is bad in an embedded system and what is due to compiler or hardware idiosyncrasies.
No, it sounds shittier than that. By either side of the decimal point, I think it meant this:
Let A and B be the positive integers you want to store. Store them as A + 1/B in a floating point number. To extract them, A = integer part, and B = 1/fractional part. (If B = 0, don't put anything in the fractional part.)
For example, 10 and 7 would become 10.142857... A = 10, and B = 1/.142857.
If you wanted to store signs, you could use the sign bit from the floating point number for one, and then for the other, remap the integers so that positive integers become positive even integers and negative integers become positive odd integers.
Yeah you can come up with mappings that can be interpreted as storing the two numbers in the two parts. But to do so you have to understand floating point representation to begin with, and and I don't think anyone who does would try to store two ints like this, rather than just writing them directly into the high and low bytes for the double.
The most likely thing IMO is that the guy posting about it didn't understand what he was reading.
This is /r/shittyprogramming so I am just going to assume it is shitty. But the method I described would work for any floating point format as long as it has sufficient precision.
5
u/alienangel2 Jun 28 '15 edited Jun 28 '15
Presumably he meant they were using the high bytes of the double for one integer and the low bytes for another, not storing string representations (which wouldn't fit in a double anyway). So the top 4 bytes of a 64bit double would store 0 as a 32bit int, and the lower 4 bytes would store 10 as another 32bit int, and there'd be no issue differentiating between 1, 10 and 100.
Still a bit pointless unless the system they're using doesn't have a compiler with things like uint32 defined, but that might actually be the case for some architectures.
If he's reading it right and it really is storing the values on sides of the decimal that is extra bizarre, since doubles are floating point. I don't think anyone would jump through the hoops needed to try to make that work, so yeah he's either making it up or misreading.
Anyway, it's not like shitty devs don't exist all over, op would find other retardedness outside of embedded. The int inside doubles thing might be justified though (actually if the c compiler is homebrewed for some obscure chip, even the code in header files might be justified). Given that OP has two weeks of experience, he probably doesn't understand what is going on enough to judge what really is bad in an embedded system and what is due to compiler or hardware idiosyncrasies.