Math with decimals problems.
neoteric
Posts: 144
I understand the BS2 does not do decimals.· I also understand there is a limit to the size number I can have.
I have a variable·A that could be any number from 1 to 5000.· I then need to take that variable, multiply it by 4,680 and divide it by 3958.
A=A*4680
A=A/3958
This would be the same as taking the variable and multiplying it by 1.1824, which is fine.
A=Z*1.1824
I have another variable, B, that could be any number from 1 to 5000.· I then need to take that variable, multiply it by 3010 and divide it by 3729.
B=B*3010
B=B/3729···· (this example is slightly different, because I am multiplying a number that is smaller than the number I am dividing by.
This would bae the same as taking the variable B and multiplying it by .0871 which is fine.
I have searched the forums, and have seen references to "this is done with subroutines..."· but I cannot find any description of how it is actually done.··· I have googled, and have tried some of thier "fixed point" logic, but have been wholely unsuccessful.·· I would really appreciate someone at the very least pointed me in the right direction....
Thanks.
I have a variable·A that could be any number from 1 to 5000.· I then need to take that variable, multiply it by 4,680 and divide it by 3958.
A=A*4680
A=A/3958
This would be the same as taking the variable and multiplying it by 1.1824, which is fine.
A=Z*1.1824
I have another variable, B, that could be any number from 1 to 5000.· I then need to take that variable, multiply it by 3010 and divide it by 3729.
B=B*3010
B=B/3729···· (this example is slightly different, because I am multiplying a number that is smaller than the number I am dividing by.
This would bae the same as taking the variable B and multiplying it by .0871 which is fine.
I have searched the forums, and have seen references to "this is done with subroutines..."· but I cannot find any description of how it is actually done.··· I have googled, and have tried some of thier "fixed point" logic, but have been wholely unsuccessful.·· I would really appreciate someone at the very least pointed me in the right direction....
Thanks.
Comments
http://www.emesystems.com/BS2math6.htm
Thanks.
To mulitply a number by a decimal, use the */ operator.· See Help section).
num = num*/$XXXX
Your decimal 1.824 has to be converted to $XXXX.· The interportion becomes $01.· The decimal portion becomes .1824 * 255 = 46.512
Round the number off to 47 and convert it to·· HEX number with your scientific calculator in Windows.· 47 = 2F, so your */ operator is $012F.
Write num = num*/$012F.
If your number was 500, then 500*/$012F = 591
500 * 4680 / 3958 = ·591.2076.
Close enough?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
First and foremost I second the suggestion you read Dr. Allen's page that LTE suggested above- however I would suggest you look at this page of his:
http://www.emesystems.com/BS2math1.htm
Now, that being said-
Consider the following:
Result = ( N */ 47 ) + N
or
Result = ( N */ 303 )
ALSO:
Result = ( N ** 11954 )
How did we get these numbers?
Remember that the */ operator is "units" of "1/256" and the ** operator is "units" of "1/65536"- so multiply your 0.1824 * 256 on a calculator. Also try it with 65536. (Why do we add the extra N in the */ example? Figure that out and you will fully understand the ** and */ operators.)
Ryan
(Sid post jumped me [noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ryan Clarke
Parallax Tech Support
RClarke@Parallax.com
((Why do we add the extra N in the */ example? Figure that out and you will fully understand the ** and */ operators.)
Because the */ only returns the lower byte.· The N thus has to be added to get the 1.x result.....
Thanks all.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax