Integer vs Real Numbers
Archiver
Posts: 46,084
Last night I was trying to define a real number with decimal in a variable and
the basic editor would not allow it. Every time I tried to put a decimal point
within a number, the editor said that I was performing an illegal binary
function, (or something like that). I checked the basic stamp manual 2.0 and
couldn't find any reference to a real number with decimals. I finally came to
the conclusion that the stamp cannot deal with decimals. Is this true?
As always, your inputs are greatly appreciated.
Thanks,
Dave Cousins
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/
the basic editor would not allow it. Every time I tried to put a decimal point
within a number, the editor said that I was performing an illegal binary
function, (or something like that). I checked the basic stamp manual 2.0 and
couldn't find any reference to a real number with decimals. I finally came to
the conclusion that the stamp cannot deal with decimals. Is this true?
As always, your inputs are greatly appreciated.
Thanks,
Dave Cousins
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/
Comments
floating point math, but there are some functions you can mess with to
overcome this sometimes, see the Parallax site for links to EME systems and
PH Anderson. Or search this egroup for your answers.
Chris
Original Message
From: david cousins <cuz_hsv@y...>
To: <basicstamps@yahoogroups.com>
Sent: Wednesday, April 04, 2001 10:22 PM
Subject: [noparse][[/noparse]basicstamps] Integer vs Real Numbers
> Last night I was trying to define a real number with decimal in a variable
and
> the basic editor would not allow it. Every time I tried to put a decimal
point
> within a number, the editor said that I was performing an illegal binary
> function, (or something like that). I checked the basic stamp manual 2.0
and
> couldn't find any reference to a real number with decimals. I finally
came to
> the conclusion that the stamp cannot deal with decimals. Is this true?
>
> As always, your inputs are greatly appreciated.
> Thanks,
> Dave Cousins
>
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> http://personal.mail.yahoo.com/
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
dealing with fixed point math, or fractions. For example, suppose you want
to know, to 1/10, what 2/3 is. You could multiply 2 x 10 to scale up for one
decimal place:
2*10 = 20
20/3 = 6 (which represents .6, which is not correct when considering
rounding, but close).
or:
2*100 = 200
200/3 = 66
66 + 5 = 71
71/10 = 7 (which represents .7, which is closer)
In the above, you are using a "guard digit".
There are more tricks you can use, but they are generally a pain.
Fractions can often work and the /* command is interesting when using
fractions. Suppose you want to multiply a number by 1.2. The equivalent
fraction is 6/5. So:
x=y*6/5
The Stamp goes right to left, so if y=9 then:
9*6 = 54 54/5 = 10 (correct answer is 10.8).
If you have small enough numbers, you might consider scaling again so you
could round correctly:
9*10 = 90 90*6 = 540 540/5 = 108 108+5 = 113 113/10 = 11
Of course, the other answer is to use a PAK-I, a PAK-II, or a PAK-IX to add
floating point math to the Stamp. The PAK-I has basic functions, while the
PAK-II adds trig and log functions. The PAK-IX is basically a PAK-II with a
5 channel 10-bit A/D converter included.
Of course, the Stamp still can't handle floating point numbers directly even
with the PAK. We provide a Windows program that can convert a number to a
hex equivalent. You can also load integers. So using our BS2 library, if you
wanted to multiply A by 1.2 directly you might write:
fpxhigh=$7F19
fpxlow=$999A ' $7F19999A is 1.2
gosub floady ' Y=1.2
fpx=A
gosub floadint ' X = variable A
gosub FMult ' X=X*Y
Now you have to read it back. If you just want to see it you could call
FDump to print the result (down to 6 decimal places). However, you can also
convert the result to an integer:
gosub FInt
B=fpx ' B is 16-bit integer result
You actually get a 24-bit result, but that's hard to work with on the Stamp.
You can modify FDump to write to an LCD or whatever. However, it is
sometimes better to scale the number to an integer as I mentioned before
when working with the Stamp. For example, suppose you want 1 decimal point
on a serial LCD or something similar. For example, suppose you have a value
in X that you want to display in the form N.N (for example, 3.7). You could
write:
fpxhigh=$8220
fpxlow=0 ' $82200000=10
gosub floady
gosub FMult
gosub FInt
' now FPX = $37
serout LCDPIN,BAUDRATE,[noparse][[/noparse]fpx/10,".",fpx//10]
That would display 3.7.
Hope that helps. You can read the PAK manuals at
http://www.al-williams.com/awce/pak1.htm
Regards,
Al Williams
AWC
*NEW: PAK-IX Floating Point A/D: http://www.al-williams.com/awce/pak9.htm
>
Original Message
> From: david cousins [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=0W5dHm_-rQ_3gX2j8II1SuRKJsbzBmth0UxM6J9hi5aoxFLsTiKaGSmp_gQTj-VZcXBrA_aEcMY]cuz_hsv@y...[/url
> Sent: Wednesday, April 04, 2001 9:22 AM
> To: basicstamps@yahoogroups.com
> Subject: [noparse][[/noparse]basicstamps] Integer vs Real Numbers
>
>
> Last night I was trying to define a real number with decimal in a
> variable and
> the basic editor would not allow it. Every time I tried to put a
> decimal point
> within a number, the editor said that I was performing an illegal binary
> function, (or something like that). I checked the basic stamp
> manual 2.0 and
> couldn't find any reference to a real number with decimals. I
> finally came to
> the conclusion that the stamp cannot deal with decimals. Is this true?
>
> As always, your inputs are greatly appreciated.
> Thanks,
> Dave Cousins
>
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> http://personal.mail.yahoo.com/
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
Doug
> To: basicstamps@yahoogroups.com
> From: david cousins <cuz_hsv@y...>
> Date: Wed, 4 Apr 2001 07:22:22 -0700 (PDT)
> Reply-to: basicstamps@yahoogroups.com
> Subject: [noparse][[/noparse]basicstamps] Integer vs Real Numbers
> Last night I was trying to define a real number with decimal in a variable and
> the basic editor would not allow it. Every time I tried to put a decimal
point
> within a number, the editor said that I was performing an illegal binary
> function, (or something like that). I checked the basic stamp manual 2.0 and
> couldn't find any reference to a real number with decimals. I finally came to
> the conclusion that the stamp cannot deal with decimals. Is this true?
>
> As always, your inputs are greatly appreciated.
> Thanks,
> Dave Cousins
>
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> http://personal.mail.yahoo.com/
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>