Sather Home Page

Section 8.2.2.1:
BIT

immutable class BIT < $IS_EQ

Inheritance map $IS_EQ

Formal Types

types
SAME = BIT ;
BIT = token

This class is a slight enhancement of the pervasive class BIT which has no conversion facilities (see create and card below). It provides the binary digit object which is the fundamental component of all objects defined in a computer system. The two possible values are setbit and clearbit.

NOTES 1. The corresponding pervasive class has no inheritance - because it is pervasive!
2. This class is defined in such a way that an implementation is not required to specify in what way the object is implemented, nor, indeed, to specify that it will always have the same implementation representation. Any use which attempts to rely on some particular representation is erroneous.

External specifications

The following feature is required to be implemented for this class in accordance with the specification given in the abstract class $IS_EQ :-


create

This creation routine returns a new binary digit. An implementation is free to implement this in any way appropriate provided only that the semantics specified here are implemented correctly.

create (
val : CARD
) : SAME
Formal Signature

create(val : CARD) res : BIT

Pre-condition

The domain of the argument is narrowed to two - the value is either 1 or 'some other numeric value'. Since this is the same size as the domain of BIT the pre-condition is vacuously true.

Post-condition
post set(res) = (val = 1)

This creation routine converts the given argument from a numeric value to a bit value. If the argument numeric value is 1 then the bit value is setbit, otherwise clearbit.


card

This conversion routine returns 1 if the bit is set, 0 if it is clear. Note that this does not constrain an implementation in the way in which it internally represents the two bit values.

card : CARD
Formal Signature
card(self : SAME) res : CARD
Pre-condition

Since the domain of the result type is larger than the domain of self, the pre-condition is vacuously true.

Post-condition
post ((res = 0)
and clear(self))
or ((res = 1)
and set(self))

This routine returns the numeric value 1 if self is set, zero if self is clear.


set

This and the following clear feature are those defined in the pervasive definition in Section 7 of this specification. They are repeated here for convenience. This feature returns true only if self is set.

set : BOOL
Formal Signature
set(self : SAME) res : BOOL
Pre-condition

Since the domain of the result has the same number of values as the domain of self then this pre-condition is vacuously true.

Post-condition
post res = (self = setbit)

This predicate returns true if and only if self has the value setbit, otherwise false.


clear

This feature is repeated here from Section 7 for convenience. It returns true if self is clear.

clear : BOOL
Formal Signature
clear(self : SAME) res : BOOL
Post-condition

Since the domain of the result has the same number of values as the domain of self then this pre-condition is vacuously true.

Post-condition
post res = (self = clearbit)

This predicate returns true if and only if self has the value clearbit, otherwise false.


Language Index Library Index Binary Index
Comments or enquiries should be made to Keith Hopper.
Page last modified: Wednesday, 22 November 2000.
Produced with Amaya