In <40uq6l$...@mark.ucdavis.edu> dpwat...@ucdavis.edu (Dan Watson) writes:

##### Quote

>Jim Waggener <crea...@infi.net> wrote:

>>I don't understand fixed point calculations in detail. Does anyone have

>>a program that shows the use of them and how they are implemented?

>Possibly I don't understand your question, but are you refering to

>"Fixed Point" numbers as enumerable types such as Word,Byte,and

>Integer, whereas Floating Point Types are like the Real type?

I think he means interpret integers to do some 'fraction-work'

EXAMPLE:

Lets say that Register AX is interpreted as follows:

AH is the whole number;

AL is the fraction:

Then the value 0.5 (1/2) is filled in like this:

AH := 0

AL := $80 (.5) (AX := $0080)

(I'm using the Intel registers for this)

If you add this number to itself,

ASM

MOV AH,$00

MOV AL,$80

ADD AX,AX

END

the result is:

AH = 1

Al = 0 ( 0.5 + 0.5 = 1.0 ...) (AX=$0100)

Subtraction works about the same, and multiplication works like this:

(I think)

ASM

MOV AX,$0080 (AX:= 0.5)

MOV BX,2 (We are going to multiply by 2; SHL's would be better)

XOR DX,DX (DX:=0 Not sure if I need to do this before mult.)

MUL AX (DX:AX := AX * AX)

END

The result is that DL contains the whole number to be

moved to AH, and AH contains the fraction to be moved to AL.

(If DH<>$00 then you have overflow (I'm only looking into UNsigned here)

Result: DX=$0000 AX=$4000

AH -> AL (AL := $40 is .25 (1/4))

DL -> AH (AH := $00 is 0)

These are the base principles of Fixed point calculation as fast

replacements of REAL's and simular stuff.

If anyone notices a mistake, please correct it, since I've never needed

FixedPointCalculations.