Decimal Math Help
Dan Cronin
Posts: 5
I'm new to this forum and PBASIC.· I'm a little stumped on how to do some decimal math and the best way to do it in PBASIC with a BS2.· Can anyone give me a tip on how to do the following equation and/or point me in the direction of some decimal math tutorials?· Thanks in advance.
Dan
a = (n / 2048) * 5
For example I have a value of 1224 for n so the answer I need is 2.988
2.988 = (1224 /2048) * 5
Dan
a = (n / 2048) * 5
For example I have a value of 1224 for n so the answer I need is 2.988
2.988 = (1224 /2048) * 5
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
For example I have a value of 1224 for n so the answer I need is 2.988
2.988 = (1224 /2048) * 5
Try this:
n*10 = 12240/(2048/10) = 12240/204 = 60
(60/10) = 6 * 5 = 3
3000/2988 = .4% error
Is that close enough?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
>> e.g. 2.988 = (1224 /2048) * 5
Hi Dan,
Here is another way to do it. Paul mentioned the */ operator, and also there is the ** operator, both of which are the Stampese way of doing fractions. Since the denominator here is 2048, an exact power of two, either one will work with good accuracy. Here it is using */.
Print "2.9882", when n=1224. The value of a is 29882.
Fractional multiply implicitly divides by 256, so on a normal calculator you can look at it like this:
a = n * 5 * 1250/256 = n * 5 * (8*1250)/(8*256) = n * 5 * 10000 / 2048
If you want a tutorial, you might peruse my math pages at
www.emesys.com/BS2index.htm#math
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
·
n = 1224···· ‘my sample input
t = 61········ ·‘sample temperature
h = 73%····· ‘ the end result humidity value using the input values above
·
a = (n/2048) * 5········ ··········‘ a=(1224/2048)*5 = 2.988
b = (a-.8)/.31···· ·················‘ b= (2.988-.8)/.031 = 70.6% Humidity
h = b/(1.093-0.0021*t)··· ·····‘ h= 70.6% / (1.093-0.0021*61) = 73% Humidity adjusted for temperature
·
I just broke it up so you can see what I’m doing.· I don’t need to hold on to the “a” and “b” values.· I just need to solve for h.· I suppose the one line formula would be:
·
h = ((((n/2048) * 5)-.8)/.31)/(1.093-0.0021*t)
·
Somewhat of a daunting task for a Stamp rookie.
·
Dan
I would suggest going through Tracy's pages. It's probably the single best resource for learning how to correctly use these operators to accomplish your goals...
Ryan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ryan Clarke
Parallax Tech Support
RClarke@Parallax.com
www.emesys.com/OL2rhtd.htm
BTW, I think there is a typo in the formula in HIH3610 data sheet, because the formula there disagrees with the formula in the HIH3602 data sheet (but the two Celsius formulae _do_ agree.) It should be (1.093-0.0012*t). It is supposed to be a linearization around 25 Celsius (77 Fahrenheit). {Note that (1.093-0.0012*t)=1.000 when t=77.5 Fahrenheit.}
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I believe you are correct and it is a Honeywell HIH-3610 Series. I'll check out your link, looks like you have lots of info and have been done this road already.
Thanks,
Dan