Mail Archives: djgpp/1997/02/04/18:57:47
Christian Tamasiu wrote:
> Why doesnt, for example, " x = y + 24 " (both x and y fixed) work???
> However, " x = y + itofix(24) " worked. But even more strange using some
> other values, it worked without itofix. It is also sometimes need using
> *,/,- and sometimes not.
> Why???
Do you know what fixed-point numbers actually are?
If not, x and y (fixed) are equal to their "integer" equivalents times
64k. So if x was 3, and y was 4, they are really 3*65536 and 4*65536.
If you use "x=y+24;" you'll get x = (4*65536) + 24, which is not much
different than y originally was.
When you use "x = y + itofix(24);" you're doing x = (4*65536) +
(24*65536).
Note that these "*65536" aren't really multiplied, but instead done by
shifting in binary (which is much faster).
The hex layout of a fixed-point number is this:
0xiiiiffff (where i is the integer part and f is the fractional part)
and the layout of a regular integer is like this:
0xiiiiiiii
Note that itofix(0x00001234) is the same as 0x12340000.
-- Yamaha / XYZZ "May farce the with be you."
mailto:scriven AT CS DOT ColoState DOT edu
mailto:scriven AT VIS DOT ColoState DOT edu
http://www.vis.colostate.edu/~scriven/
- Raw text -