| 12-13-2003, 09:33 PM | #1 |
Alright, I've no idea how to use these functions you guys made I'll be honest. Right now I decided I'd create a polynomial handling function set. That takes many assumption into place. It assumes that this is arranged like so Cn*X^N+Cn-1*X^(N-1)...+C0*X^0. That is no term is repeated, and that its in decending order of power. You also right now need to right out what power it is, and what coeffecient (even if its 1 or 0) it has. It also assumes that the maxium exponent is 9 (any more and it stops reading tokens). I have a function that rips out tokens of each polynomial part. And then assigns them to a coeffecient array. (where the constant value is at 0 and the N value is the last definable spot). Problem is I like to be able to return this array, and use other functions which will take this array. I understand I could use this heap thing to define an array, I'd like to know how. |
| 12-13-2003, 10:29 PM | #2 |
I assume that your coefficients are reals. If they are integers it becomes easier as you won't need the conversions. Code:
function Int2Real takes integer i returns real if i != 0 then return i endif return 0.0 endfunction function Real2Int takes real r returns integer if r != 0.0 then return r endif return 0 endfunction ... local integer my_array = HeapNew(10) // that gives you the amount of memory you need as you need to store 10 numbers ... // Now you can do whatever you want to do with the array on the heap call HeapSet(my_array + i, Real2Int(x)) // stores the real x in my_array at position i (position starting with 0) // in normal arrays that would be: set my_array[i] = x set x = Int2Real(HeapGet(my_array+i)) // retrieves the position i from my_array and stores it in x // in normal arrays that would be: set x = my_array[i] call HeapDelete(my_array, 10) That frees this part of the memory so it can be reused by HeapNew. |
| 12-13-2003, 11:07 PM | #3 |
Thanks AiAndy, this heap stuff is really cool. But I don't see how you can use my_array outside of the local function where its defined... Edit I'm an idiot. |
