Re: in which form real and integer values are saved in memory



Keith Thompson <kst-u@xxxxxxx> writes:

Tim Rentsch <txr@xxxxxxxxxxxxxxxxxxx> writes:
Keith Thompson <kst-u@xxxxxxx> writes:
Charlton Wilbur <cwilbur@xxxxxxxxxxxxxx> writes:
"BP" == Ben Pfaff <blp@xxxxxxxxxxxxxxx> writes:

BP> Ed Prochak <edprochak@xxxxxxxxx> writes:

>> intergers may be big endian or little endian, ones complement or
>> twos complement, BCD or others.

BP> I don't think that BCD is a valid representation for C integer
BP> types.

...unless there's no way for a conforming program to know the
difference.

It would be difficult to arrange that, though not impossible.

Depending on how this statement is meant, the proposition is
either trivially true or wrong.

Clearly a C implementation can use BCD to encode C values
using the simple trick of having one BCD digit per bit.
One octet (two nibbles) would hold two C "bits", or four
octets per char (with CHAR_BIT == 8).

That's not what I had in mind.

However, if "representation" is meant in the sense that
the Standard uses the term (as in "object representation",
for example), integers cannot be represented using
BCD, as that is not consistent with other requirements
for representation of integers.

What I was thinking of was an implementation that uses BCD for integer
representation (so that a stored bit pattern of 0001 0101 represents
the value 15), but that goes through substantial gyrations to make it
*appear* to be using a pure binary representation. If you examined
the underlying representations of objects using, say, a debugger,
you'd see the BCD, but the BCD representation wouldn't leak out to
become visible in the behavior of any program that avoids undefined
behavior. The implementation would satisfy the "least requirements"
of C99 5.1.2.3p5.

Yes, that would be another way of doing it. At the far end of the
spectrum, the entire program state could be represented as one
gigantic BCD-encoded integer (which would mean decoding/encoding
essentially the entire program state at every point). Just as silly
(or even sillier?), but of course the point is to ask whether it
can be done, not how useful it is.


This would be a very difficult and silly thing to do, but I'm not
convinced it would violate the standard.

The counterargument is that the representation requirements of 6.2.6.1
must be met by the underlying representation, and that satisfying
5.1.2.3p5 is insufficient.

To put it another way, it should be possible to implement C on top of
a binary virtual machine running on BCD hardware.

Right. BCD encoding (or any other computable encoding) is allowed
in the underlying hardware, but not in the C virtual machine.
.



Relevant Pages

  • Re: What about big integers in Ada 2005?
    ... > BCD was originally a six bit representation. ... > the advent of the byte on the IBM System 360, BCD became Extended Binary ... The 6-bit character code was BCDIC -- Binary Coded Decimal Interchange ... > in the picture and a nibble for the sign. ...
    (comp.lang.ada)
  • Re: in which form real and integer values are saved in memory
    ... >> intergers may be big endian or little endian, ... >> twos complement, BCD or others. ... BP> I don't think that BCD is a valid representation for C integer ...
    (comp.lang.c)
  • Re: in which form real and integer values are saved in memory
    ... >> intergers may be big endian or little endian, ... >> twos complement, BCD or others. ... BP> I don't think that BCD is a valid representation for C integer ...
    (comp.lang.c)
  • Re: understanding floats
    ... > exercise) to write floating point math routines that represent numbers ... > an analogous problem for a base 10 representation when dealing with ... and represented BCD numbers in 80 bits. ... I also seem to recall the ...
    (comp.lang.lisp)
  • Re: Currency Rounding Errors
    ... BCD offers no significant advantages over fixed-point binary. ... representation of 1234 was, in fact, the characters "1234". ... own data type and writing your own operations on that data type. ... "decimal fixed-point and floating-point are still important and continue ...
    (microsoft.public.vc.mfc)