Finite Field Arithmetic

fz_lim.adb


   1 ------------------------------------------------------------------------------
   2 ------------------------------------------------------------------------------
   3 -- This file is part of 'Finite Field Arithmetic', aka 'FFA'.               --
   4 --                                                                          --
   5 -- (C) 2019 Stanislav Datskovskiy ( www.loper-os.org )                      --
   6 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html     --
   7 --                                                                          --
   8 -- You do not have, nor can you ever acquire the right to use, copy or      --
   9 -- distribute this software ; Should you use this software for any purpose, --
  10 -- or copy and distribute it to anyone or in any manner, you are breaking   --
  11 -- the laws of whatever soi-disant jurisdiction, and you promise to         --
  12 -- continue doing so for the indefinite future. In any case, please         --
  13 -- always : read and understand any software ; verify any PGP signatures    --
  14 -- that you use - for any purpose.                                          --
  15 --                                                                          --
  16 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm .     --
  17 ------------------------------------------------------------------------------
  18 ------------------------------------------------------------------------------
  19 
  20 package body FZ_Lim is
  21    
  22    -- Determine if a proposed FFA Bitness is valid.
  23    function FZ_Valid_Bitness_P(B : in Positive) return Boolean is
  24       Result   : Boolean := False;
  25       T        : Natural := B;
  26       PopCount : Natural := 0;
  27    begin
  28       -- Supposing we meet the minimal bitness:
  29       if B >= FZ_Minimal_Bitness then
  30          while T > 0 loop
  31             PopCount := PopCount + T mod 2;
  32             T := T / 2;
  33          end loop;
  34          
  35          -- Is B a power of 2?
  36          if PopCount = 1 then
  37             Result := True;
  38          end if;
  39       end if;
  40       
  41       return Result;
  42    end FZ_Valid_Bitness_P;
  43    
  44 end FZ_Lim;