PIC specific math@ (including trigonometric functions sin(), arctan(), etc.), SX specific math@, Intel specific math@
Dr Dobbs Journal #271 pg 18 "A Conversation with William Kahan" William Kahan "Formulas that are numerically stable are sometimes quite inelegant. Formulas that give you greater accuracy are sometimes full of cases, ugly cases.... F(x)=(sin x)/x .... F(x)=(sin x)/x if x != 0 and F(0) = 1"
Have ex-mathematicians become dysfunctional?
See also:
Books
Math:
If you've got a basket with 3 oranges in it and you take 5 out, then you have to put 2 oranges in again in order for it to be empty. -- Peter Gutmann
Questions:
Hi there, I am having trouble with arithmetic in assembler. I want to do the following calculation:
Y = ((X-Xmin)((Ymax-Ymin)/(Xmax-Xmin))) + Ymin This is a formula to scale a point between Xmax and Xmin to a point between Ymax and Ymin. The Y points is 8-bit but the X points can be up to 16-bit values. You can already see my problem because I cannot get any 16-bit divided by 16-bit algorith or for that matter 24-bit divided by 16-bit that replies with the fractional part. So I came up with the next formula to try and use a 16-bit divided by 8-bit number to give back fractions:
Y = ((X-Xmin)(1/(Xmax-Xmin)/(Ymax-Ymin))) + Ymin But it just gets more complex as I go along. My second problem is that say I work out the division and now I must multiply the answer (which is fractional , how the hell do you do it with the fractional part. Do you first multiply both numbers so they are integer and then divide it again later with the same number or what. Am I even on the right track here or am I going bananas? Please help me I am now three months into the game and have learned a lot in a short space of time but the learning just seems to grow and not level out, not that I am complaining just a remark:-)
Rearrange the formula so that the top and bottom of the fraction is kept
seperate. What you really want is:
Y = ((X-Xmin)(Ymax-Ymin) + Ymin(Xmax-Xmin)) over Xmax-Xmin.
Now you can do the top and bottom seperatly. Multiplying by a fraction is
a seperate job but can still be done without division. It is a good
idea to reduce the fraction after each operation to prevent overflow. A method
for doing that is available but I can't find it at the moment.
Once you have the final answer, then you do the division.
See: