Adriaan van Os wrote:
Frank Heckenbach wrote:
Perhaps I'm too much a mathematician to ever understand such motivations.
<snip>
My suggestion would be:
Numbers are interpreted in the mathematical sense (i.e., positive, as long as they don't contain a `-' sign etc.).
`not', `and', `or' and `xor' are conceptually defined as functions on the integer numbers (defined such that they correspond to the bit operations given a sufficiently large representation), see appendix.
<snip>
Appendix: Mathematical definition of "bit" functions
And I am too much a programmer to understand mathematicians ...
Looking at the mathematical definitions some more, aren't we transforming back bitwise operations and a specific bitwise notational convention (two's complement) back into mathematics ?
Yes.
If so, isn't it true that:
- the mathematical definitions aren't universal mathematical
definitions, independent of bit conventions
No, that's not true. They're defined as integer functions, using nothing but simple operations such as `+', `-' and comparisons. Indeed, you could perform those operations with decimal numbers if you like. It's a bit more complicated to compute, but in the end you'll get the same results.
- the bit-level definitions are simpler
Indeed, and a real implementation (on a machine using binary two's complement numbers, as virtually any machine today does) would usually use them. (Unless, perhaps, you want to provide those operations on a pure standard Pascal system, without escaping to the underlying hardware. If you don't care about efficiency, you could indeed implement them this way.)
As I tried to explain, the definitions are there so we compare the behaviour of an implementation against a well-defined result. E.g., if there are corner-cases or cases where different implementations behave differently, we can use it to decide which one to accept. If we achieve this (we yet have to check and possibly correct it in GPC), a programmer can use those operations and rest assured that they behave the same, whatever the underlying hardware does.
This principle is similar with `mod' semantics. With negative operands, different CPUs behave differently (there was a thread on this list about this issue long time ago, you might find it in the archive if you care). Yet ISO Pascal defines the semantics uniquely (and so does BP -- unfortunately in a different way), so any implementation can do what's necessary to map the CPU result to the desired result (which may be nothing if it matches or some extra code, such as GPC uses, since e.g. on i386, it doesn't match).
Frank