[BACK]Return to standard_integer_norms.adb CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / PHC / Ada / Math_Lib / Matrices

File: [local] / OpenXM_contrib / PHC / Ada / Math_Lib / Matrices / standard_integer_norms.adb (download)

Revision 1.1.1.1 (vendor branch), Sun Oct 29 17:45:24 2000 UTC (23 years, 7 months ago) by maekawa
Branch: PHC, MAIN
CVS Tags: v2, maekawa-ipv6, RELEASE_1_2_3, RELEASE_1_2_2_KNOPPIX_b, RELEASE_1_2_2_KNOPPIX, RELEASE_1_2_2, RELEASE_1_2_1, HEAD
Changes since 1.1: +0 -0 lines

Import the second public release of PHCpack.

OKed by Jan Verschelde.

with Standard_Common_Divisors;           use Standard_Common_Divisors;

package body Standard_Integer_Norms is

  function gcd ( v : Vector ) return integer is

    tmp : Vector(v'range);
    res : integer;

  begin
    for i in v'range loop
      if v(i) < 0
       then tmp(i) := -v(i);
       else tmp(i) :=  v(i);
      end if;
    end loop;
    res := tmp(tmp'first);
    for i in (tmp'first+1)..tmp'last loop
      res := gcd(res,tmp(i));
      exit when (res = 1);
    end loop;
    return res;
  end gcd;

  procedure Normalize ( v : in out Vector ) is

    g : constant integer := gcd(v);

  begin
    if (g /= 0) and then (g /= 1)
     then for i in v'range loop
            v(i) := v(i)/g;
          end loop;
    end if;
  end Normalize;

end Standard_Integer_Norms;