Need some help on some math issues in spin
radialrandy
Posts: 78
rpm1 := ((1_200_000_000/(b-a))* scale)*2 This is giving me results that Im not happy with. this calculation gives me "rpm1" results that incriments of 8 in decimal. example 5060, 5068....even though the "b-a" gives big numbers. I attached a snapshot of my debug terminal results so u can see the varying b-a numbers and the rpm1 numbers. I would think the calculation should be accurate enough to give me results to the 1 decimal. example 5060,5061,5062..... What am i missing here?
thanks
thanks
Comments
For example, right off the bat, you are multiplying your results by 2, so no matter what you are always going to get something that is a multiple of 2, same goes for scale, so the idea here is to make sure that you pre-divide anything out yourself, so that the results are to the 1's place.
Another idea if you want more accuracy is to use fixed point math or the floating point library.
But, this is a simple matter of you are scaling your results after the fact that's why you have this *8 in there, anything *8 is *8. There are no fractions or decimals here, so that's what is causing the issue.
Andre'
Since you're using integer math, doing the scale up at the end is losing intermediate precision.
Try scaling (b-a) down instead of scaling the result back up, like this:
rpm1 := 1_200_000_000 / ((b-a) / (scale*2))