]> gcc.gnu.org Git - gcc.git/commitdiff
[Ada] Provide new function Uintp.UI_To_Unsigned_64
authorArnaud Charlet <charlet@adacore.com>
Mon, 8 Mar 2021 12:13:43 +0000 (07:13 -0500)
committerPierre-Marie de Rodat <derodat@adacore.com>
Thu, 17 Jun 2021 14:32:11 +0000 (10:32 -0400)
gcc/ada/

* uintp.ads, uintp.adb (UI_To_Unsigned_64): New.

gcc/ada/uintp.adb
gcc/ada/uintp.ads

index 045b8e53d881f5cdf790ec1f7dcecf0b22ba7654..8183469ca9bfa98e9eae78cbda2d3c4fbdd133b7 100644 (file)
@@ -2179,9 +2179,9 @@ package body Uintp is
       end if;
    end UI_To_CC;
 
-   ----------------
+   ---------------
    -- UI_To_Int --
-   ----------------
+   ---------------
 
    function UI_To_Int (Input : Uint) return Int is
       pragma Assert (Input /= No_Uint);
@@ -2230,6 +2230,46 @@ package body Uintp is
       end if;
    end UI_To_Int;
 
+   -----------------
+   -- UI_To_Uns64 --
+   -----------------
+
+   function UI_To_Unsigned_64 (Input : Uint) return Unsigned_64 is
+      pragma Assert (Input /= No_Uint);
+
+   begin
+      if Input < Uint_0 then
+         raise Constraint_Error;
+      end if;
+
+      if Direct (Input) then
+         return Unsigned_64 (Direct_Val (Input));
+
+      --  Case of input is more than one digit
+
+      else
+         if Input >= Uint_2**Int'(64) then
+            raise Constraint_Error;
+         end if;
+
+         declare
+            In_Length : constant Int := N_Digits (Input);
+            In_Vec    : UI_Vector (1 .. In_Length);
+            Ret_Int   : Unsigned_64 := 0;
+
+         begin
+            Init_Operand (Input, In_Vec);
+
+            for Idx in In_Vec'Range loop
+               Ret_Int :=
+                 Ret_Int * Unsigned_64 (Base) + Unsigned_64 (In_Vec (Idx));
+            end loop;
+
+            return Ret_Int;
+         end;
+      end if;
+   end UI_To_Unsigned_64;
+
    --------------
    -- UI_Write --
    --------------
index 04657027fd9e8b00a671992f7130e7bde379fcb0..607e7ef95fa3056ad59027582f3738e336e1e97d 100644 (file)
@@ -252,6 +252,11 @@ package Uintp is
    --  Converts universal integer value to Int. Constraint_Error if value is
    --  not in appropriate range.
 
+   type Unsigned_64 is mod 2**64;
+   function UI_To_Unsigned_64 (Input : Uint) return Unsigned_64;
+   --  Converts universal integer value to Unsigned_64. Constraint_Error if
+   --  value is not in appropriate range.
+
    function UI_To_CC (Input : Uint) return Char_Code;
    --  Converts universal integer value to Char_Code. Constraint_Error if value
    --  is not in Char_Code range.
This page took 0.067615 seconds and 5 git commands to generate.