home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / eiffel / smalleif.97 / se.t / SmallEiffel / lib_std / integer_ref.e < prev    next >
Encoding:
Text File  |  1996-05-02  |  2.5 KB  |  128 lines

  1. -- Part of SmallEiffel -- Read DISCLAIMER file -- Copyright (C) 
  2. -- Dominique COLNET and Suzanne COLLIN -- colnet@loria.fr
  3. --
  4. class INTEGER_REF
  5.  
  6. inherit
  7.    NUMERIC
  8.       redefine
  9.      infix "+", infix "-", infix "*", infix "/",
  10.      infix "^", prefix "-", prefix "+", valid_divisor,
  11.      one, zero
  12.       end;
  13.    COMPARABLE
  14.       redefine infix "<", compare, hash_code 
  15.       end;
  16.    
  17. creation {ANY}
  18.    make
  19.    
  20. feature {ANY}
  21.  
  22.    item: INTEGER;
  23.    
  24.    make(value: INTEGER) is
  25.       do
  26.      item := value
  27.       end;
  28.    
  29.    infix "+" (other: like Current): like Current is
  30.      -- Add `other' to Current.
  31.       do
  32.      !!Result.make (item + other.item)
  33.       end;
  34.    
  35.    infix "-" (other: like Current): like Current is
  36.      -- Subtract `other' from Current.
  37.       do
  38.      !!Result.make (item - other.item)
  39.       end;
  40.  
  41.    infix "*" (other: like Current): like Current is
  42.      -- Multiply `other' by Current.
  43.       do
  44.      !!Result.make (item * other.item)
  45.       end;
  46.  
  47.    infix "/" (other: like Current): DOUBLE_REF is
  48.      -- Divide Current by `other'.
  49.      -- Note: Integer division
  50.       do
  51.      !!Result.make (item / other.item)
  52.       end;
  53.  
  54.    infix "//" (other: like Current): like Current is
  55.      -- Divide Current by `other'.
  56.      -- Note : Integer division
  57.       require
  58.      valid_divisor (other)
  59.       do
  60.      !!Result.make (item // other.item)
  61.       end;
  62.  
  63.    infix "\\" (other: like Current): like Current is
  64.      -- Remainder of division of Current by `other'.
  65.       require
  66.      valid_modulus: valid_divisor (other)
  67.       do
  68.      !!Result.make (item \\ other.item)
  69.       end;
  70.  
  71.    infix "^" (exp: INTEGER): like Current is
  72.      -- Raise Current to `exp'-th power.
  73.       do
  74.      !!Result.make (item ^ exp)
  75.       end;
  76.  
  77.    infix "<" (other: like Current): BOOLEAN is
  78.      -- Is Current less than `other'?
  79.       do
  80.      Result := (item < other.item)
  81.       end;
  82.  
  83.    prefix "+": like Current is
  84.       do
  85.      !!Result.make (item)
  86.       end;
  87.  
  88.    prefix "-": like Current is
  89.      -- Unary minus of Current
  90.       do
  91.      !!Result.make (-item)
  92.       end;
  93.  
  94.    compare (other: like Current): INTEGER is
  95.      -- Compare Current with `other'.
  96.      -- '<' <==> Result < 0
  97.      -- '>' <==> Result > 0
  98.      -- Otherwise Result = 0
  99.       do
  100.      Result := item - other.item
  101.       end;
  102.  
  103.    hash_code: INTEGER is
  104.       do
  105.      if item < 0 then
  106.         Result := -item
  107.      else
  108.         Result := item
  109.      end;
  110.       end;
  111.  
  112.    valid_divisor(other: like Current): BOOLEAN is
  113.       do
  114.      Result := (other.item /= 0)
  115.       end;
  116.  
  117.    one: like Current is
  118.       do
  119.      !!Result.make (1)
  120.       end;
  121.  
  122.    zero: like Current is
  123.       do
  124.      !!Result.make (0)
  125.       end;
  126.  
  127. end -- class INTEGER_REF
  128.