From: SerDevian Newsgroups: comp.os.msdos.djgpp Subject: Re: Allegro fixed math routines Date: Tue, 04 Feb 1997 14:20:43 -0700 Organization: XYZZ Software Co. Lines: 33 Message-ID: <32F7A82B.446B@CS.ColoState.edu> References: NNTP-Posting-Host: miro.vis.colostate.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp 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/