Brandon Keepers - I am seeing a lot of variance...
I am seeing a lot of variance in the precision of my NMEA data coming through Signal K. Here is an example of the values collected by the bathymetry plugin I'm working on. This is the data collection in a 5 second window.
I'm trying to figure out if this is the NMEA data coming in, or something happening in JavsScript/Signal K. It smells like the classic issue with JavaScript representing floating point numbers (e.g. 0.1 + 0.2 = 0.30000000000000004). I have the raw NMEA data too, but I'm still trying to figure out how to extract the values for comparison. Any pointers?
I'm trying to figure out if this is the NMEA data coming in, or something happening in JavsScript/Signal K. It smells like the classic issue with JavaScript representing floating point numbers (e.g. 0.1 + 0.2 = 0.30000000000000004). I have the raw NMEA data too, but I'm still trying to figure out how to extract the values for comparison. Any pointers?
7 Replies
Get canboat and canboatjs, you can use their command line tools and compare the output.
I would be very surprised if it was an issue with the code. Way too many people would notice
And. Of course, I don’t write software that has bugs in it! 🤣
I have the raw NMEA data too, but I'm still trying to figure out how to extract the values for comparison.https://gpsd.io/
@Brandon Keepers I was assuming n2k?
@Scott Bender yes, I'm seeing it on two different NMEA 2000 networks with different hardware, one using the PICAN-M + Vesper XB 8000 + Raymarine ST60, the other using iKonvert + USB puck GPS + Garmin Intelliducer.
The precision variance effects all data I'm looking at (GPS, heading, depth) and really smells like the JavaScript floating point issue.
I'm guessing nobody has noticed because it's not a problem in practice. The difference between -81.71273599999999 and -81.712736 is mm, which is much less than the accuracy of the sensor
Would definitely be interesting to compare canboat and canboatjs output.
And I should write some tests that compare the two…
I'll grab some data and compare it in a little bit. I'm currently working on getting my dinghy-powered survey vessel operational for a field test tomorrow. I'm hoping to survey a shoal in the St John/Ortega River in Jacksonville.
In the mean time, I'm just using
toFixed
to convert back to expected precision: https://github.com/bkeepers/signalk-bathymetry/blob/main/src/streams/transforms.ts#L4-L22As a C / C++ / Rust person I'm not sure what the "Javascript floating point" issue is, but it sure looks like typical floating point to decimal conversion issues to me. Remember that FP represents fractions with combinations of binary digits, so it can represent 0.5, 0.25, 0.125 etc exactly but the rest is just an approximation. You should use a limited decimal representation anywhere you convert from FP to a decimal string.