Hello All, I am having trouble working with fractions within my project. I am using a DSP56F826 chip with Codewarrior tools. I am trying to create functions that will convert fractional data (Frac16 and Frac32) into int and long int data. Does anyone know how to do this either in C or in assembly? Thanks, Brad |
|
fractional number
RE: [motoroladsp] fractional number
Frac16 and Fract32 are representations of the values +1.0 to -1.0 so to convert them to an integer, just multipy them by the range you wish to represent. For example: to have a range of -100 to 100, multiply the Fractxx value by 100. Another way to look at this is to think in terms of the
following equation:
So, multiplying a Fract16 by the maximum integer value yields the represented integer value. If your range of integer values happens to be +32767 to -32768, then the Fract16 value is the corresponding integer value!!! Jerry. -----Original Message-----
Hello All, I am having trouble working with fractions within my
project. I am
I am trying to create functions that will convert fractional
data
Does anyone know how to do this either in C or in assembly? Thanks, Brad ------------------------ Yahoo! Groups Sponsor
---------------------~-->
_____________________________________
_____________________________________
To Join: m...@yahoogroups.com To Post: m...@yahoogroups.com To Leave: m...@yahoogroups.com Archives: http://www.yahoogroups.com/group/motoroladsp More Groups: http://www.dsprelated.com/groups.php3
________________________________________________________________________
________________________________________________________________________ This email has been scanned for all viruses by the MessageLabs SkyScan service. For more information visit http://www.messagelabs.com ________________________________________________________________________ |
Brad, Maybe you can use the following macros provided in SDK to assist you in the conversion from fractional to integer: #define FRAC16(x) ((Frac16)((x) < 1 ? ((x) >= -1 ? (x)*0x8000 : 0x8000) : 0x7FFF)) #define FRAC32(x) ((Frac32)((x) < 1 ? ((x) >= -1 ? (x)*0x80000000 : 0x80000000) : 0x7FFFFFFF)) and as an example you can use them as: UWord16 Int16 = FRAC16(0.25) UWord32 Int32 = FRAC32(0.75) Hope this helps. Best regards, Fabio Estevam -----Original Message----- From: bblaundry [mailto:] Sent: segunda-feira, 1 de mar de 2004 16:17 To: Subject: [motoroladsp] fractional number Hello All, I am having trouble working with fractions within my project. I am using a DSP56F826 chip with Codewarrior tools. I am trying to create functions that will convert fractional data (Frac16 and Frac32) into int and long int data. Does anyone know how to do this either in C or in assembly? Thanks, Brad _____________________________________ Note: If you do a simple "reply" with your email client, only the author of this message will receive your answer. You need to do a "reply all" if you want your answer to be distributed to the entire group. _____________________________________ About this discussion group: To Join: To Post: To Leave: Archives: http://www.yahoogroups.com/group/motoroladsp More Groups: http://www.dsprelated.com/groups.php3 Yahoo! Groups Links |