math calculations with a decimal result
gc3076
Posts: 44
is there a way to get a decimal result on a math calculation with the BS2.
simple i.e 1/3= 0.333
simple i.e 1/3= 0.333
Comments
Look for the Long Division for Duty Cycle Calculations section.
Post Edited (Andy Lindsay (Parallax)) : 1/20/2006 6:29:34 PM GMT
operator, another is the ** operator.· Both are explained in the Help file.
For the example you posted, you could write:
x = 1000/3
debug ".", dec x· 'debug would display .333
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
http://www.emesystems.com/BS2math6.htm
Thanks.
These are probably two of the most useful math operators available on the BASIC Stamp. · These operators allow the BASIC Stamp to do fractions, breaking the barrier of integer math. ·These operators will come up time and time again as we come up with solutions to practical calculation problems using the BASIC Stamp and as we·move on to "higher" math with the BASIC Stamp.
...
The way the BS2 manual explains the */ command is technical:
It helps to recall (or to learn!) that dropping the 8 least significant bits of a binary number is equivalent to dividing the number by 28=256. That is precisely what the */ operator does. It implicitly performs the division by 256
The ** operator is similar, in that it takes the top 16 bits of the product. It drops the 16 least significant bits of the 32 bit product, in effect performing an implicit division by 216=65536. In the Stamp manual, the ** operator is explained in the context of double precision math. That is one use of it. This fractional multiplication is another. If you read through these math pages, ** turns up in all sorts of surprising places.
The full text is here: http://www.emesystems.com/BS2math1.htm
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10