Integer-only math
arnold113
Posts: 43
in BASIC Stamp
Is there a work around for this equation? (x = diameter / square root of 2). I've got a on going project
that I need to be able to obtain the largest square contained inside a circle. I'm using the BS2P40 with v2.5
editor. I need to be able to start with a dia. of say 15.3" and use 1.414 as the divisor (square root of 2).
I have built a portable band saw sawmill and I'm using the BS2p40 to control operation of the sawmill. I need of find the largest square (cant) that can be sawed from a log. Any help will be appreciated.
Thanks, Arnold
that I need to be able to obtain the largest square contained inside a circle. I'm using the BS2P40 with v2.5
editor. I need to be able to start with a dia. of say 15.3" and use 1.414 as the divisor (square root of 2).
I have built a portable band saw sawmill and I'm using the BS2p40 to control operation of the sawmill. I need of find the largest square (cant) that can be sawed from a log. Any help will be appreciated.
Thanks, Arnold
Comments
You want the constant to be as large as possible without overflowing (+/- 32767).
So you might use a constant of 1,000. That would allow a log with a 32" diameter.
Then instead of dividing by root 2, multiply by 1/root 2 and use the ** operator.
The ** operator multiplies two values and returns the upper 16 bits of the result.
So it is like A**B = ((A*B) / 65536) it is okay if A*B is larger than 32767 because it is held as 32 bits internally.
So 1/root 2 = 0.70710678 we multiply that by 65536 for the ** operator to get 46341 (rounded to closest int).
So the equation becomes x = 15300 ** 46341 which would make x equal to 10818 (or 10.818") and is calculated as ((15300 * 46341) / 65536).
I hope this helps,
Bean
Thanks again.
Arnold