Re: Representing decimal part as regular integer on low 16 bits?




Jean-François Michaud wrote:
Hello,

I was exploring this idea and I was wondering if anybody had any
thoughts concerning this.

I was thinking that the decimal part of a decimal number could be
directly converted to its "integer" representation on the low end of 16
bits.

0.325 would basically show up like this on the hex side within 32 bits

0x00000145

If we decide to fix decimals to 3 positions, this means that everytime
we are over 0x3E8 (decimal 1000), we transfer a unit on the integer
part of the 32 bits

0x00001450 + 0x00001450 + 0x00001450 + 0x00001450 = 0x00005140

so we transfer the unit over.

0x514 - 0x3E8 = 0x12C

0x000112C0.

Substraction would be similar.

I see that this potentially involves more manipulations, but it seems
that this way, no precision is lost, no rounding error will occur and
we don't need to convert to hex/binary representation. I haven't
explored multiplication or division much yet, but...

0x145 * 0x145 = 0x19C99 which corresponds exactly to 0.105625 (should
be 6 digits)

In the case of the fractional part, 0x145 doesn't mean the same as
0x0145

Anybody tried something like this?

Regards
Jeff

Hmmm Interresting. BCD without actually using BCD format.

Regards
Jean-Francois Michaud

.



Relevant Pages

  • Representing decimal part as regular integer on low 16 bits?
    ... I was exploring this idea and I was wondering if anybody had any ... If we decide to fix decimals to 3 positions, ... that this way, no precision is lost, no rounding error will occur and ... we don't need to convert to hex/binary representation. ...
    (comp.lang.forth)
  • Re: Binary coded fixed point decimal
    ... If I want 3 digit of decimal precision then I have to adjust by 1000. ... Jean-Francois Michaud ... Anybody every play with the remainder when normalizing fixed-point ...
    (comp.lang.forth)
  • Re: Binary coded fixed point decimal
    ... I was wondering how fixed point decimals are usually converted to ... hex/binary representation. ... entered by users are not actual numbers but graphic representation, ... Jean-Francois Michaud ...
    (comp.lang.forth)