|
|
 | | From: | Eric Meurville | | Subject: | C code for fixed point atan2 | | Date: | Thu, 20 Jan 2005 18:34:07 +0100 |
|
|
 | Hello,
I have to implement atan2 on a dsPIC30F and would like to do that in fixed point for reasonable performance. Does someone already did that?
Thanks, -- Eric Meurville
|
|
 | | From: | Nithin | | Subject: | Re: C code for fixed point atan2 | | Date: | 20 Jan 2005 14:42:46 -0800 |
|
|
 | Hi You may want to look a this http://dspguru.com/comp.dsp/tricks/alg/fxdatan2.htm
-Nithin
|
|
 | | From: | Eric Meurville | | Subject: | Re: C code for fixed point atan2 | | Date: | Fri, 21 Jan 2005 10:46:18 +0100 |
|
|
 | Thanks for the link but the code proposed uses floats and I would perform the computation with integers.
EMe.
Nithin wrote: > Hi > You may want to look a this > http://dspguru.com/comp.dsp/tricks/alg/fxdatan2.htm > > -Nithin >
|
|
 | | From: | Steve Underwood | | Subject: | Re: C code for fixed point atan2 | | Date: | Fri, 21 Jan 2005 19:10:01 +0800 |
|
|
 | Hi Eric,
Look again. The example code may use floats, but the title is "fixed point atan2 with self-normalisation". If you recast the numbers as fixed point values it works just fine.
Regards, Steve
Eric Meurville wrote:
> Thanks for the link but the code proposed uses floats and I would > perform the computation with integers. > > EMe. > > Nithin wrote: > >> Hi >> You may want to look a this >> http://dspguru.com/comp.dsp/tricks/alg/fxdatan2.htm >> >> -Nithin >>
|
|
 | | From: | bungalow_steve at yahoo.com | | Subject: | Re: C code for fixed point atan2 | | Date: | 21 Jan 2005 09:18:17 -0800 |
|
|
 | Steve Underwood wrote: > bungalow_steve@yahoo.com wrote: > > Steve Underwood wrote: > > > >>Hi Eric, > >> > >>Look again. The example code may use floats, but the title is "fixed > >>point atan2 with self-normalisation". If you recast the numbers as > > > > fixed > > > >>point values it works just fine. > >> > >>Regards, > >>Steve > >> > >> > >>Eric Meurville wrote: > >> > >> > >>>Thanks for the link but the code proposed uses floats and I would > >>>perform the computation with integers. > >>> > >>>EMe. > >>> > >>>Nithin wrote: > >>> > >>> > >>>>Hi > >>>>You may want to look a this > >>>>http://dspguru.com/comp.dsp/tricks/alg/fxdatan2.htm > >>>> > >>>>-Nithin > >>>> > > > > > > if you simply recast everything as integers, won't coeff_1 =0? and what > > do you do with 1e-10? > > > > Who said anything about using integers. I said fixed point. You don't
> even have to think about the 1e-10. A comment tells you why it is there, > and it is, therefore, trivial to eliminate it with a bit of logic. The > logic doesn't work so well with floats, which I guess is why the > original is kludged in that way. > > Regards, > Steve
There is a fixed point data type in C?
|
|
 | | From: | Jerry Avins | | Subject: | Re: C code for fixed point atan2 | | Date: | Fri, 21 Jan 2005 12:49:19 -0500 |
|
|
 | bungalow_steve@yahoo.com wrote:
...
> There is a fixed point data type in C?
Fixed-point is at worst integer scaled by shifts. Compilers for some processors that have fixed-point hardware do support a fixed-point type. Without that, either do the job in assembler or write C-callable assembly routines for best execution speed.
Jerry -- Engineering is the art of making what you want from things you can get. ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
|
|
 | | From: | Ronald H. Nicholson Jr. | | Subject: | Re: C code for fixed point atan2 | | Date: | Fri, 21 Jan 2005 19:21:39 +0000 (UTC) |
|
|
 | In article <1106327897.743543.57540@z14g2000cwz.googlegroups.com>, wrote: >> Who said anything about using integers. I said fixed point. .... >There is a fixed point data type in C?
Yes, indirectly. The meaning of the bits in (int/short/long) are defined by the programmer. For instance they can represent boolean flags instead of any scalar quantity. If LSB represents a unit quantity, then you might have traditional integers. But the LSB can also represent a fractional quantity, for instance, cents instead of dollars if you don't want to lose pennies in certain types of financial arithmetic. The LSB can also represent 1/256th's, or other 1/(2^n)th's, if you want normalization or renormalization to be easily done using the << and >> C operators.
Normalize for any input or output, and renormalize after any multiply or divide, and the (int/short/long) C data types can be used to represent fixed point or scaled integer values of the appropriate range and accuracy.
IMHO. YMMV. -- Ron Nicholson rhn AT nicholson DOT com http://www.nicholson.com/rhn/ #include // only my own opinions, etc.
|
|
 | | From: | Steve Underwood | | Subject: | Re: C code for fixed point atan2 | | Date: | Mon, 24 Jan 2005 15:02:52 +0800 |
|
|
 | This is a multi-part message in MIME format. --------------020006080406080906020401 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit
Ronald H. Nicholson Jr. wrote:
>In article <1106327897.743543.57540@z14g2000cwz.googlegroups.com>, > wrote: > > >>>Who said anything about using integers. I said fixed point. >>> >>> >... > > >>There is a fixed point data type in C? >> >> > >Yes, indirectly. The meaning of the bits in (int/short/long) are >defined by the programmer. For instance they can represent boolean flags >instead of any scalar quantity. If LSB represents a unit quantity, then >you might have traditional integers. But the LSB can also represent a >fractional quantity, for instance, cents instead of dollars if you don't >want to lose pennies in certain types of financial arithmetic. The LSB can >also represent 1/256th's, or other 1/(2^n)th's, if you want normalization >or renormalization to be easily done using the << and >> C operators. > >Normalize for any input or output, and renormalize after any multiply >or divide, and the (int/short/long) C data types can be used to represent >fixed point or scaled integer values of the appropriate range and accuracy. > >IMHO. YMMV. > > I think it is interesting to note that various older languages - Algol, Coral, PL/1 - had explicit support for fixed point arithmetic. I think Ada still does (its years since I touched it), but it seems to be missing for other currently popular languages. Its value was somewhat limited in the older languages. It was generally rather implementation dependant, so code tended not to be very portable. It is, however, something of a pity that you now have to use vanilla integers, and do all the fiddley bits yourself. You may end up with the same result, but the code lacks clarity.
That said, if you can't see that any language supporting integers also supports fixed point you've failed arithmetic 101. :-)
Regards, Steve
--------------020006080406080906020401 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit
Ronald H. Nicholson Jr. wrote:
In article <1106327897.743543.57540@z14g2000cwz.googlegroups.com>, <bungalow_steve@yahoo.com> wrote: Who said anything about using integers. I said fixed point.
... There is a fixed point data type in C?
Yes, indirectly. The meaning of the bits in (int/short/long) are defined by the programmer. For instance they can represent boolean flags instead of any scalar quantity. If LSB represents a unit quantity, then you might have traditional integers. But the LSB can also represent a fractional quantity, for instance, cents instead of dollars if you don't want to lose pennies in certain types of financial arithmetic. The LSB can also represent 1/256th's, or other 1/(2^n)th's, if you want normalization or renormalization to be easily done using the << and >> C operators.
Normalize for any input or output, and renormalize after any multiply or divide, and the (int/short/long) C data types can be used to represent fixed point or scaled integer values of the appropriate range and accuracy.
IMHO. YMMV.
I think it is interesting to note that various older languages - Algol, Coral, PL/1 - had explicit support for fixed point arithmetic. I think Ada still does (its years since I touched it), but it seems to be missing for other currently popular languages. Its value was somewhat limited in the older languages. It was generally rather implementation dependant, so code tended not to be very portable. It is, however, something of a pity that you now have to use vanilla integers, and do all the fiddley bits yourself. You may end up with the same result, but the code lacks clarity.
That said, if you can't see that any language supporting integers also supports fixed point you've failed arithmetic 101. :-)
Regards,
Steve
--------------020006080406080906020401--
|
|
 | | From: | glen herrmannsfeldt | | Subject: | Re: C code for fixed point atan2 | | Date: | Fri, 21 Jan 2005 13:37:56 -0800 |
|
|
 | Ronald H. Nicholson Jr. wrote: (someone asked)
>>There is a fixed point data type in C?
> Yes, indirectly. The meaning of the bits in (int/short/long) are > defined by the programmer. For instance they can represent boolean flags > instead of any scalar quantity. If LSB represents a unit quantity, then > you might have traditional integers. But the LSB can also represent a > fractional quantity,
It would be much easier with a multiply that returned a 2N bit product, and a divide that took a 2N bit dividend. That is the way it is done in hardware, mostly for this reason. (The other reason is to allow implementing multiple precision arithmetic.)
-- glen
|
|
 | | From: | bungalow_steve at yahoo.com | | Subject: | Re: C code for fixed point atan2 | | Date: | 21 Jan 2005 09:39:40 -0800 |
|
|
 | Microchip might be implementing more terms in the polynomial, I suspect if you implemented the code in integer math on the dsPIC the entire function would execute in less time then a single floating point add. If I remember correctly the integer divide is the killer, 18 cycles, but even with that, your talking at most 25-30 cycles for the entire integer algorithm compared with over 100 cycles for a single floating addition.
|
|
 | | From: | bungalow_steve at yahoo.com | | Subject: | Re: C code for fixed point atan2 | | Date: | 21 Jan 2005 06:45:00 -0800 |
|
|
 | Steve Underwood wrote: > Hi Eric, > > Look again. The example code may use floats, but the title is "fixed > point atan2 with self-normalisation". If you recast the numbers as fixed > point values it works just fine. > > Regards, > Steve > > > Eric Meurville wrote: > > > Thanks for the link but the code proposed uses floats and I would > > perform the computation with integers. > > > > EMe. > > > > Nithin wrote: > > > >> Hi > >> You may want to look a this > >> http://dspguru.com/comp.dsp/tricks/alg/fxdatan2.htm > >> > >> -Nithin > >>
if you simply recast everything as integers, won't coeff_1 =0? and what do you do with 1e-10?
|
|
 | | From: | Steve Underwood | | Subject: | Re: C code for fixed point atan2 | | Date: | Sat, 22 Jan 2005 00:14:35 +0800 |
|
|
 | bungalow_steve@yahoo.com wrote: > Steve Underwood wrote: > >>Hi Eric, >> >>Look again. The example code may use floats, but the title is "fixed >>point atan2 with self-normalisation". If you recast the numbers as > > fixed > >>point values it works just fine. >> >>Regards, >>Steve >> >> >>Eric Meurville wrote: >> >> >>>Thanks for the link but the code proposed uses floats and I would >>>perform the computation with integers. >>> >>>EMe. >>> >>>Nithin wrote: >>> >>> >>>>Hi >>>>You may want to look a this >>>>http://dspguru.com/comp.dsp/tricks/alg/fxdatan2.htm >>>> >>>>-Nithin >>>> > > > if you simply recast everything as integers, won't coeff_1 =0? and what > do you do with 1e-10? >
Who said anything about using integers. I said fixed point. You don't even have to think about the 1e-10. A comment tells you why it is there, and it is, therefore, trivial to eliminate it with a bit of logic. The logic doesn't work so well with floats, which I guess is why the original is kludged in that way.
Regards, Steve
|
|
 | | From: | Eric Meurville | | Subject: | Re: C code for fixed point atan2 | | Date: | Fri, 21 Jan 2005 16:55:34 +0100 |
|
|
 | I agree, this code is definetely floating point. Nevertheless, its performance on dsPIC30F is 3 times better than Microchip native math library.
bungalow_steve@yahoo.com wrote: > Steve Underwood wrote: > >>Hi Eric, >> >>Look again. The example code may use floats, but the title is "fixed >>point atan2 with self-normalisation". If you recast the numbers as > > fixed > >>point values it works just fine. >> >>Regards, >>Steve >> >> >>Eric Meurville wrote: >> >> >>>Thanks for the link but the code proposed uses floats and I would >>>perform the computation with integers. >>> >>>EMe. >>> >>>Nithin wrote: >>> >>> >>>>Hi >>>>You may want to look a this >>>>http://dspguru.com/comp.dsp/tricks/alg/fxdatan2.htm >>>> >>>>-Nithin >>>> > > > if you simply recast everything as integers, won't coeff_1 =0? and what > do you do with 1e-10? >
-- Eric Meurville
|
|
|