View Full Version : Floating point tables in Flash
I have existing code that creates a table of integer values like this
CREATE FUNC1
1 P, 2 P, 3 P,
EEWORD
I can then retrieve the values like this, for example the second value
FUNC1 1 + P@
How do I do the equivalent for Floating point values? I tried this
CREATE FUNC1
1.0E0 F, 1.5E0 F, 1.6E0 F,
EEWORD
But I can't figure out how to get the values back. P@ has two problems, it fetches to the integer stack and it always returns -1. For example
FUNC1 2 + P@ FUNC1 3 + P@ .S
Should print the two words representing 1.5E0 but instead it prints
-1
-1 OK
RMDumse
03-04-05, 10:03 PM
Your problem is there is no PF@.
But, you can work around it. Realize, a float and a double take the same amount of space. You can work through an intermediate RAM location. So you should be able to use the F, to install the values, then get them with a
DUP P@ SWAP 1+ P@
(If this returns the words in the wrong order, just move the 1+ to the other P@.)
2VARIABLE TEMP
Anyway, you'll now have a double on the stack. Store it in a temporary RAM location with 2!, then F@ the same address to get it to the floating point stack.
DUP P@ SWAP 1+ P@ TEMP 2! TEMP F@
Yeah, I tried a couple of things like that. Here is an example
SCRUB
IsoMax V0.74
DECIMAL OK
CREATE FUNC1 OK
1.1E0 F, 1.2E0 F, 1.3E0 F, 1.4E0 F, OK
DVARIABLE TEMP OK
FUNC1 DUP 1 + P@ SWAP P@ TEMP D! TEMP F@ OK
FUNC1 DUP P@ SWAP 1 + P@ TEMP D! TEMP F@ OK
F.S
7.7144E-39 1.2122E-38 > 2 OK
CREATE FUNC2 OK
FUNC2 DUP P@ .S
30210
32283 OK
1.1E0 F, OK
FUNC2 DUP P@ .S
30210
32283
30210
32283 OK
It doesn't look like F, is modifying memory at all. What am I doing wrong? Is there a better way to create these tables? I need a persistent table of values for generating a function by interpolation.
RMDumse
03-05-05, 06:34 PM
Come to think of it, there's no PF, either.
F, is storing a value in Data RAM, not in Program Flash.
Let me work on this now that I'm seeing the problem a bit more clearly, and am actually talking to a board where I can test code as I go.
OK, I think I figured it out.
F, is like , not P, which is why there is no PF@.
Here is what I came up with. I put the table in RAM which is less than ideal, but I think all my tables will be small enough to be OK.
RMDumse
03-05-05, 08:35 PM
I've worked through it. Here you can see an example of something you could use.
COLD
DVARIABLE TEMP
: F!-P, TEMP F! TEMP @ P, TEMP 1+ @ P, ;
: P@-F@ DUP P@ TEMP ! 1+ P@ TEMP 1+ ! TEMP F@ ;
CREATE FUNC1
1.1E0 F!-P, 1.2E0 F!-P, 1.3E0 F!-P, 1.4E0 F!-P,
FUNC1 P@-F@ F.
FUNC1 2 + P@-F@ F.
FUNC1 4 + P@-F@ F.
FUNC1 6 + P@-F@ F.
Ahhh.. OK. That is just what I needed. Thanks for your help.
vBulletin v3.0.7, Copyright ©2000-2012, Jelsoft Enterprises Ltd.