home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-04-13 | 2.7 KB | 139 lines | [TEXT/ttxt] |
- -- Part of SmallEiffel -- Read DISCLAIMER file -- Copyright (C)
- -- Dominique COLNET and Suzanne COLLIN -- colnet@loria.fr
- --
- class INTEGER_REF
-
- inherit
- NUMERIC
- undefine out_in_tagged_out_memory, fill_tagged_out_memory
- redefine
- infix "^", prefix "-", prefix "+"
- end;
- COMPARABLE
- redefine compare, hash_code, out_in_tagged_out_memory,
- fill_tagged_out_memory
- end;
-
- creation make
-
- feature
-
- item: INTEGER;
-
- make(value: INTEGER) is
- do
- item := value
- end;
-
- feature
-
- set_item(value: like item) is
- do
- item := value;
- end;
-
- infix "+" (other: like Current): like Current is
- -- Add `other' to Current.
- do
- !!Result.make (item + other.item)
- end;
-
- infix "-" (other: like Current): like Current is
- -- Subtract `other' from Current.
- do
- !!Result.make (item - other.item)
- end;
-
- infix "*" (other: like Current): like Current is
- -- Multiply `other' by Current.
- do
- !!Result.make (item * other.item)
- end;
-
- infix "/" (other: like Current): DOUBLE_REF is
- -- Divide Current by `other'.
- -- Note: Integer division
- do
- !!Result.make (item / other.item)
- end;
-
- infix "//" (other: like Current): like Current is
- -- Divide Current by `other'.
- -- Note : Integer division
- require
- valid_divisor (other)
- do
- !!Result.make (item // other.item)
- end;
-
- infix "\\" (other: like Current): like Current is
- -- Remainder of division of Current by `other'.
- require
- valid_modulus: valid_divisor (other)
- do
- !!Result.make (item \\ other.item)
- end;
-
- infix "^" (exp: INTEGER): like Current is
- -- Raise Current to `exp'-th power.
- do
- !!Result.make (item ^ exp)
- end;
-
- infix "<" (other: like Current): BOOLEAN is
- -- Is Current less than `other'?
- do
- Result := (item < other.item)
- end;
-
- prefix "+": like Current is
- do
- !!Result.make (item)
- end;
-
- prefix "-": like Current is
- -- Unary minus of Current
- do
- !!Result.make (-item)
- end;
-
- compare (other: like Current): INTEGER is
- -- Compare Current with `other'.
- -- '<' <==> Result < 0
- -- '>' <==> Result > 0
- -- Otherwise Result = 0
- do
- Result := item - other.item
- end;
-
- hash_code: INTEGER is
- do
- if item < 0 then
- Result := -item
- else
- Result := item
- end;
- end;
-
- valid_divisor(other: like Current): BOOLEAN is
- do
- Result := (other.item /= 0)
- end;
-
- one: like Current is
- do
- !!Result.make (1)
- end;
-
- zero: like Current is
- do
- !!Result.make (0)
- end;
-
- out_in_tagged_out_memory, fill_tagged_out_memory is
- do
- item.fill_tagged_out_memory;
- end;
-
- end -- INTEGER_REF
-