You are reading a single comment by @AkosLukacs and its replies.
Click here to read the full conversation.
-
A re-implementation from the original C line
uint64_t frf = ((uint64_t)val << 19) / 32000000;
can be re-written to C code using floating point numbers
uint64_t frf = (uint64_t)((float)val * 0.016384);
and then converted to JavaScript:
var frf = Math.round(val * 0.016384);
(0.016384 is equal to Math.pow(2, 19) / 32000000)
Sat 2019.07.27
Sort of agree with you but, . . . as @AkosLukacs and yourself have pointed out, and with the note in the link from #10 that I found, there is an issue (fewer identical upper MSB values-see your #9) with the floating point values compared with other means. This severely (in my need) affects accuracy where the LSB bits will be needed. My suggestion for an attempt with inline 'C' might bypass what the Javascript Math library does, which is dependent on floating point. Don't know if the inline 'C' functions might use the identical floating point mechanism at the hardware level. i.e. Math.pow() is the library layer on top of the Espruino Javascript layer on top of inline 'C' asm on top of the physical hardware layer itself.
EDIT:
Note to @Gordon would you briefly describe how the floating point section works to build it's values please, and maybe where in the source they are extracted. Are log tables used? More of a curiosity question as I hadn't realized how complex doing 'simple' math actually is for a micro.
Just thought of a possible hacky solution using the original Arduino script. As my design will require the end user to input one of only 20 to 50 valid values using this C++ function conversion, I could possibly write a small Arduino code file and build a table of those values that it puts out. Then using an array or switch case code block in Javascript, extract the hex bits already converted that way. This would however, make for headaches for future user update requests of the finished deployed module.
Naaaahh, as a purist, I'll wait and see if we can find a Javascript solution.