Hi all, iIn visual studio 2010, I'm doing 1/a where "a" is a fixed-point number. "a" receives numbers between 30-60 and the problem is that I get zeros for all of them when doing 1/a; even though "a" is a fixed- type with 32 integer bits and 50 non-integer bits. Can you guide me how to solve this problem? Thanks, Elnaz
fixed-point division
Started by ●November 19, 2011
Reply by ●November 19, 20112011-11-19
Elnaz wrote:> Hi all, > > iIn visual studio 2010, I'm doing 1/a where "a" is a fixed-point > number. "a" receives numbers between 30-60 and the problem is that I > get zeros for all of them when doing 1/a; even though "a" is a fixed- > type with 32 integer bits and 50 non-integer bits. Can you guide me > how to solve this problem? > > Thanks, > ElnazProbably not. What does "32 integer bits and 50 non-integer bits" mean? Can't you use floating point? SFAIK, 64 bit computers support 64 bit floating point in hardware.... -- Les Cargill
Reply by ●November 19, 20112011-11-19
On Sat, 19 Nov 2011 16:27:13 -0800, Elnaz wrote:> Hi all, > > iIn visual studio 2010, I'm doing 1/a where "a" is a fixed-point number. > "a" receives numbers between 30-60 and the problem is that I get zeros > for all of them when doing 1/a; even though "a" is a fixed- type with 32 > integer bits and 50 non-integer bits. Can you guide me how to solve this > problem?What processor are you using that has 82-bit data paths? And what data type is 'a'. If it really has fractional bits, then you should get a non-zero answer. So you're either using the wrong data type, you're using the right data type the wrong way (if it's C and you're typing '1/a' then you're using it the wrong way), or Visual Studio has a horrendous bug. Tell us more pertinent info. -- www.wescottdesign.com
Reply by ●November 19, 20112011-11-19
I'm converting floating-point implementation to fixed-point for future use in hardware implementation of the same code. The floating-point version is absolutely fine and working. The fixed-point definition type I set: ac_fixed <W, I, true, AC-RND, AC-SAT> with W (the whole word length)=64, and I(integer bits)= 32. And, I'm doing 1/a (a is a defined as above) and yes, it's C. So, I don't know where I'm doing wrong?
Reply by ●November 19, 20112011-11-19
On Sat, 19 Nov 2011 17:23:37 -0800, Elnaz wrote:> I'm converting floating-point implementation to fixed-point for future > use in hardware implementation of the same code. The floating-point > version is absolutely fine and working. The fixed-point definition type > I set: ac_fixed <W, I, true, AC-RND, AC-SAT> with W (the whole word > length)=64, and I(integer bits)= 32. And, I'm doing 1/a (a is a defined > as above) and yes, it's C. So, I don't know where I'm doing wrong?Without knowing what shenanigans Visual Studio is playing with C, I would expect that you would need to do the divide by calling some library function or macro that aliases integer types into the desired fixed point type. C, by itself, does not support any fixed-point types other than integers. -- Tim Wescott Control system and signal processing consulting www.wescottdesign.com
Reply by ●November 19, 20112011-11-19
Reply by ●November 19, 20112011-11-19
Reply by ●November 20, 20112011-11-20
On 11/19/11 10:26 PM, Elnaz wrote:> Does anyone have a C function for division in fixed-point? >do you want a snippet of C code that computes the bits in division as if the "/" operator didn't exist? or do you want a snippet of C code that uses integer division and fiddles with the scaling necessary to do fixed-point division? (the latter is easier than the former, but if you're trying to implement division in an FPGA or in some crude processor, you might need the former.) -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Reply by ●November 20, 20112011-11-20
On Sat, 19 Nov 2011 19:26:09 -0800, Elnaz wrote:> Does anyone have a C function for devision in fixed-point?Yes, but that's not what you want. What you want is to figure out how to call the fixed-point division function in whatever library you're using. You said in an earlier post (whose context you haven't kept -- this _is_ USENET, you know):>> The fixed-point definition type I set: ac_fixed <W, I, true, AC-RND, >> AC-SAT> with W (the whole word length)=64, and I(integer bits)= 32.That looks like a pretty specific syntax, which implies a library -- shouldn't there just be a fixed-point division library function? -- www.wescottdesign.com
Reply by ●November 20, 20112011-11-20
Tim <tim@seemywebsite.please> wrote: (snip)> Without knowing what shenanigans Visual Studio is playing with C, I would > expect that you would need to do the divide by calling some library > function or macro that aliases integer types into the desired fixed point > type.> C, by itself, does not support any fixed-point types other than integers.Well, C does have shift operators that sometimes can do what is needed. Also, many compilers will recognize a product of 32 bit values cast to (long long) and do a 32x32 --> 64 multiply. Some might also recognize a 64 bit dividend for a 32 bit quotient, though I don't know that I ever checked for that. The OP can try to cast the dividend to (long long), shift left the appropriate number of bits, then divide. But yes, C doesn't help all that much. -- glen






