Main Site Documentation

Critical flaw in Elze Kool's exMath lib


Skewworks and I were troubleshooting some issues I was having with my geo distance calculations, when Skew noticed something interesting. The cause of the problems was the fact that Elze didn’t define PI properly in his lib!

Replace line 45 with

public static readonly double PI = 3.1415926535897931F;

… and the issue should be fixed.

It might also be worth checking the other constants in the lib, as well.

Elze, if you are reading this, no hard feelings or anything! Little mistake, but I wanted people to be aware of it to avoid further confusion. :slight_smile:


Any reason you are using this instead on the GHI native math lib?


Not really at the moment, no. I was using it for my Geo libs because I wanted to see the code behind the methods, and I also wanted to create something that would be cross compatible with other NETMF boards. I’ll also have target specific versions in the end.


why are you assigning a float to a double, chris?


Don’t ask me, it’s Elze’s library!

There are lots in that library that could be improved. My aim wasn’t to do that, only to fix the immediate issue.


A double will store the value of Pi far more accurately than float will (twice as accurately actually hehe… since it’s a Double over a Single). The F at the end should be a D though…

As a little test though:

            float pif = 3.1415926535897931f;
            double pid = 3.1415926535897931d;
            double pifd = 3.1415926535897931f;

Actual values upon execution: (from locals window)

		pif	3.14159274	float
		pid	3.1415926535897931	double
		pifd	3.1415927410125732	double