Square root issue

I was developing my first app and kept having the app crash when running on my watch (Pebble Time 2) in certain situations, while it worked fine in the emulator. I eventually tracked down the issue to the sqrt() function being pulled in from the standard <math.h> library.

It seems that on the watch, the sqrt function works fine when the number passed in is a perfect square, but doesn’t calculate it properly otherwise. I haven’t figured out exactly what it does in those scenarios, but I would suspect it’s returning NaN or similar.

Not an urgent issue for me, because I don’t need an exact value and was able to put in a “good enough” algorithm for my purpose. But it might trip up some others, especially since the emulator seems to calculate the square roots correctly regardless of input.

2 Likes