-
Ah, now I got it. That's why I asked @Robin what is this about. And reading the latest comment, turns out it's just a piece of random code...
Sooooooo, originally Semtech gives users a formula in chapter 4.1.4! you don't need 64 bit integer, or more precise FP, just do the math, and multiply with 0.016384! as @maze1980 already pointed out. And now 915e6 makes sense as well: 915MHz frequency.
Quick aside: a good compiler probably can optimize away the bit shift and division, so the programmer just leaves it there instead of manually calculating / simplifying the formula. And most likely easier to follow the code.
1 Attachment
While
((uint64_t)val << 19) / 32000000
does no rounding, but you still have some loss in accuracy unless the number is an integer multiple of "32000000". The final result has only three bytes, as needed for the next steps.I'm too lazy to test the result in JavaScript using a 64 bit math module vs. normal numbers, but in C it is like this:
If you want to see more than "Hello World", "Done" change
b = (__uint64_t)((double)i * 0.016384);
tob = (__uint64_t)((float)i * 0.016384);
.For me it doesn't look like there's any need to shift ones and zeros. Think about it.
@AkosLukacs:
The source is most likely this file here, found by searching for "<< 19) / 32000000".
For the linked code: A 32 bit frequency value is taken as input, converted to 24 bit (three byte values) with a loss in accuracy of 8 bit.