At 01:11 PM 10/15/2005 -0400, you wrote: >At 09:34 AM 10/15/2005 -0700, you wrote: >> > How would you calculate e^(-at) in 32 bit integer math? >> > >> > Why does it need to be integer math? From your previous post >> > I got the impression this calculation was going to be done at >> > assembly time. >> >>The assembler I'm using only supports integer math. No fractions. No >>floating point. Just integers. So if you put in .36 it becomes 0. 92/256 = >>0. Integer math. > >Okay so you imagine a radix point at an appropriate place. You can move >it around after each intermediate calculation with shifts, provided you >don't overflow. Unfortunately, you've got to deal with "C-like" integer >math and don't have access to the full 64-bits of a multiply, only the >least significant 32 bits. > >For example, 0.36 might be represented as 0x0002E14 (0.36 * 32768). The >radix point is between the MS 2 bytes and the LS 2 bytes. > >>How do you calculate e^(-x) where x is between 1/256 and 192/256 using only >>integer math. > >A Taylor series might do it acceptably well. James: Here is an example in c, where xf, yf are 32-bit integers. xf = x * 128; yf = 32768 - xf + (xf* xf)/65536 - (((xf * xf)/32768 )*xf)/(6*32768) + (((xf*xf)/32768)* ((xf*xf)/32768))/(32768 * 24) - (((((xf*xf)/32768)* ((xf*xf)/32768))/32768) * xf)/(32768 * 120) ; The result is ~= exp(-x/256) * 32768 over the range x = 1 to 192. yf/32768 agrees with exp(-x/256) within 0.001 over that range. You can easily extend this to additional terms, although it gets a bit tedious. It's based on the textbook Taylor/Maclaurin series infinity --- \ exp(x) = > (x^n)/n! / --- n= 0 Best regards, ---- Tria -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist