long pageWidth = machineWidth * stepsPerMM;
float pageWidth_fp = (float)pageWidth;
float getCartesianXFP(float aPos, float bPos) {
float calcX = (sq(pageWidth_fp – sq(bPos) + sq(aPos))
/ (pageWidth_fp * 2.0);
return calcX;
}
You could also pick up some more performance by eliminating the (pageWidth_fp * 2.0) calculation since it is always the same value by assigning it to a static variable inside the function.
float getCartesianXFP(float aPos, float bPos) {
static float twoTimesPageWidth = pageWidth_fp * 2.0;
float calcX = (sq(pageWidth_fp – sq(bPos) + sq(aPos))
/ twoTimesPageWidth;
return calcX;
}