Re: fixed-point
From: pout (pout_at_work.com)
Date: 04/10/04
- Next message: Anthony Wong: "Re: Avoiding redundant functions"
- Previous message: Martin Ambuhl: "Re: simple problem"
- In reply to: Malcolm: "Re: fixed-point"
- Next in thread: Malcolm: "Re: fixed-point"
- Reply: Malcolm: "Re: fixed-point"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 10 Apr 2004 04:13:09 GMT
Malcolm <malcolm@55bank.freeserve.co.uk> wrote in message
news:c579ai$br7$1@news6.svr.pol.co.uk...
> "pout" <pout@work.com> wrote in message news:L4Edc.1914
> >
> > When you say "a certain range", do you mean the range that can be
> > represented by the format of fixed-point, like 16.16, its range is
> > 0000.0000 ~ FFFF.FFFF?
> >
> That's right. Fixed point can be signed or unsigned. If all your values
are
> in the range +- 30000 and you don't need greater precision than 0.0001 (1
in
> 10,000) then you can consider fixed point with 16:16 bits.
> > > Shall it be 8 bits instead of 16 in: #define Int2Fixed(x) (((long)
> > >(short)x) << 24)?
> > What exactly is accomplished by left-shifting 24 bits?
> >
> If we have the integer value 15 (0x0F) it becomes 0x000F000000 in the
fixed
> point representation.
> >
> > How to apply "Int2Fixed" and "Fixed2Int" in real calculation? For >
> example,
> >
> > int a, b;
> >
> > How to do addition, subtraction, multiplication and division with a
> > and b that involves "fixed-point" type?
> >
> To add or subtract two fixed point numbers, simply add or subtract them.
> Multipication is the tricky part. All values are scaled up by 16 bits, so
> you have to correct
>
> (a * b) >> 16;
>
> (or as you did it, calling the FixedToInt() macro).
> The problem is that on many compilers you will get overflow, since the
> product of two 32 bit numbers is a 64 bit number. This can be solved by a
> smidgeon of assembly, or sometimes by a judicious cast to long long.
> >
> > and in case of a/b,
> >
> > int d = Fixed2Int(Int2Fixed(a) / Int2Fixed(b));
> >
> There are two answers here.
> 1) You want the result as an integer. Simply divide two fixed point
numbers.
> 2) You wnat the result in fixed point format. You have to left shift the
> numerator before you do the divide
>
> x = (num << 16) / denom;
>
This is much clearer to me now.
According to what you said, whenever two numbers in division, to get a
result of fixed point, change either numerator or denominator to fixed point
format. Right?
After having the result in fixed point, will chaning the result back to int
make the number of fixed point lose its precision? Or make the conversion
to fixed point and back to int the same as a division of two ints?
Thanks!
- Next message: Anthony Wong: "Re: Avoiding redundant functions"
- Previous message: Martin Ambuhl: "Re: simple problem"
- In reply to: Malcolm: "Re: fixed-point"
- Next in thread: Malcolm: "Re: fixed-point"
- Reply: Malcolm: "Re: fixed-point"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|