Double word in tp7?
Author Message
Double word in tp7?

Is there a way to create a type which defines a doubleword in tp7? I
*really* need to have one, because the longint range is (of course) only
half, and goes negative the same way, but I don't need the negative part.
Can one replace the sign-bit or is the dword type definable.

Lots of thanks, Astro/Acid

Wed, 18 Jun 1902 08:00:00 GMT
Double word in tp7?

Quote:

> Is there a way to create a type which defines a doubleword in tp7? I
> *really* need to have one, because the longint range is (of course) only
> half, and goes negative the same way, but I don't need the negative part.
> Can one replace the sign-bit or is the dword type definable.

> Lots of thanks, Astro/Acid

I had that problem too. Well, no, it's not possible.
Maybe you can use the comp type. But: consider that it is not a genuine
integer type, but in fact a floating point type.

Wed, 18 Jun 1902 08:00:00 GMT
Double word in tp7?

Quote:

>Is there a way to create a type which defines a doubleword in tp7? I
>*really* need to have one, because the longint range is (of course) only
>half, and goes negative the same way, but I don't need the negative part.
>Can one replace the sign-bit or is the dword type definable.

Just disable the overflow checking and you can do addition, subtraction
and multiplication(*). For division where the dividend has high bit set
you need your own routines. Then of course you need to write routines
to translate to and from ASCII and comparisons.

(*) Signed and unsigned multiplications are identical as far as only the
lower 32 bits are considered. They do differ with the 32 bits that are
carried out but as those are not relevant in Pascal (beyond error
detection) one can use the signed multiplication for unsigned one.

Or if you have 386+ you could use following:

Function Dmul(x,y:longint):longint;
inline(
\$66/\$5B/             {POP     EBX}
\$66/\$58/             {POP     EAX}
\$66/\$F7/\$E3/         {MUL     EBX}
\$66/\$0F/\$A4/\$C2/\$10  {SHLD    EDX,EAX,10h}
);

Function DDiv(x,y:longint):longint;
inline(
\$66/\$5B/             {POP     EBX}
\$66/\$58/             {POP     EAX}
\$66/\$31/\$D2/         {XOR     EDX,EDX}
\$66/\$F7/\$F3/         {DIV     EBX}
\$66/\$0F/\$A4/\$C2/\$10  {SHLD    EDX,EAX,10h}
);

For comparison you could XOR the both parts with \$8000000, that is
instead of if x<y then ...  write if x xor \$80000000 < y xor \$80000000
then ...  (of course you could define a constant for that value). You
could also subtract the above value from both. I have not tested that.

If you need to test only equality then there is no need for such
tricks.

Osmo

Wed, 18 Jun 1902 08:00:00 GMT
Double word in tp7?
Then the integer operations have to be redefined:

A DIV B => Int(A / B)
A MOD B => A - (A DIV B) * B

If you want, you can also define like that:

A DIV B =>
T := A / B;
IF T < 0 THEN T := Int(T + 1) ELSE T := Int(T)
A MOD B => A - (A DIV B) * B

Quote:

> > Is there a way to create a type which defines a doubleword in tp7? I
> > *really* need to have one, because the longint range is (of course)
only
> > half, and goes negative the same way, but I don't need the negative
part.
> > Can one replace the sign-bit or is the dword type definable.

> > Lots of thanks, Astro/Acid

> I had that problem too. Well, no, it's not possible.
> Maybe you can use the comp type. But: consider that it is not a genuine
> integer type, but in fact a floating point type.

Wed, 18 Jun 1902 08:00:00 GMT

 Page 1 of 1 [ 4 post ]

Relevant Pages