A cheeky ask...
I am trying to output the result of X / Y. I suspect it would be easy using a Floating Point Unit or FPU and then picking the digits one by one off the left of an output string discarding initial zeros. That it what I would do in my other programming domains. But, this needs to be battery powered!
I have an ugly algorithm, but I suspect it could be improved in many ways. I could not even say it is bug free. I do not feel it is worth showing!
I am sure others have solved this division, but I could not find it with a quick search. Some signposting is needed. If there is a documented working programme that does this, just a pointer might suffice for me to work it out.
I hope to use an 18m2.
Over time both X and Y will change by incrementing, so I wish to loop and display the current, but changing value of X / Y say every 10 seconds while data slowly accumulates independently in X and Y.
I am not trying to achieve huge precision, as this would be artificial, so 3 significant digits would be fine/ adequate.
I need flexibility, as I do not know whether X or Y will be bigger, as either might be the case i.e. the answer might be more or less than 1.
I need the digits of the answer one at a time from the left in order to display them.
Leading Zeros to be suppressed.
Zeros preferably before a decimal point if less than 1 e.g. 0.654
Both X and Y will be always be independently incrementing positive integers greater than 0 and in word sized variables, but I would like to be able to use the maximum extent of these, to allow X and or Y to grow as big as possible before being 'full'.
Ideally rounding would be conventional rather than just a truncation.
The data in X and Y changes slowly over time so great speed is very unlikely to be required.
I think recursive solutions would not go well with a Picaxe?
Examples of arbitrary snapshots of inputs and outputs...
So for momentary example values of...
X / Y = 1st, 2nd, 3rd digit (one may be with a decimal point)
250 / 5 = 5, 0., 0
255 / 5 = 5, 1., 0
22 / 3 = 7., 3, 3
40 / 100 = 0., 4, 0
64000 / 32000 = 2., 0, 0
I hope that is enough examples to get the idea. I hope I have described the problem, succinctly.
I am struggling to find an efficient, tidy but general solution which is likely to be bug free.
Please don't tackle this unless it appeals to you as I know it is a cheeky ask, but others might be interested in the solution? Can a Picaxe do this? HertzHog.
I am trying to output the result of X / Y. I suspect it would be easy using a Floating Point Unit or FPU and then picking the digits one by one off the left of an output string discarding initial zeros. That it what I would do in my other programming domains. But, this needs to be battery powered!
I have an ugly algorithm, but I suspect it could be improved in many ways. I could not even say it is bug free. I do not feel it is worth showing!
I am sure others have solved this division, but I could not find it with a quick search. Some signposting is needed. If there is a documented working programme that does this, just a pointer might suffice for me to work it out.
I hope to use an 18m2.
Over time both X and Y will change by incrementing, so I wish to loop and display the current, but changing value of X / Y say every 10 seconds while data slowly accumulates independently in X and Y.
I am not trying to achieve huge precision, as this would be artificial, so 3 significant digits would be fine/ adequate.
I need flexibility, as I do not know whether X or Y will be bigger, as either might be the case i.e. the answer might be more or less than 1.
I need the digits of the answer one at a time from the left in order to display them.
Leading Zeros to be suppressed.
Zeros preferably before a decimal point if less than 1 e.g. 0.654
Both X and Y will be always be independently incrementing positive integers greater than 0 and in word sized variables, but I would like to be able to use the maximum extent of these, to allow X and or Y to grow as big as possible before being 'full'.
Ideally rounding would be conventional rather than just a truncation.
The data in X and Y changes slowly over time so great speed is very unlikely to be required.
I think recursive solutions would not go well with a Picaxe?
Examples of arbitrary snapshots of inputs and outputs...
So for momentary example values of...
X / Y = 1st, 2nd, 3rd digit (one may be with a decimal point)
250 / 5 = 5, 0., 0
255 / 5 = 5, 1., 0
22 / 3 = 7., 3, 3
40 / 100 = 0., 4, 0
64000 / 32000 = 2., 0, 0
I hope that is enough examples to get the idea. I hope I have described the problem, succinctly.
I am struggling to find an efficient, tidy but general solution which is likely to be bug free.
Please don't tackle this unless it appeals to you as I know it is a cheeky ask, but others might be interested in the solution? Can a Picaxe do this? HertzHog.