comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced?
Date: Sat, 29 Jul 2023 23:43:53 -0500	[thread overview]
Message-ID: <ua4ppq$2smlt$1@dont-email.me> (raw)
In-Reply-To: 2a5702b3-dbbc-4255-a4d4-e801f227fed3n@googlegroups.com

'Image doesn't support any formatting, so no "Aft" or "Exp". The slicing 
isn't the problem. :-)

You can use Text_IO to write to a string if you need formatting. 'Image is 
for quick & dirty debugging, not fancy output. (Of course, if you're lucky 
and it does what you need, then feel free to use it.)

                                 Randy.

"Kenneth Wolcott" <kennethwolcott@gmail.com> wrote in message 
news:2a5702b3-dbbc-4255-a4d4-e801f227fed3n@googlegroups.com...
On Saturday, July 29, 2023 at 4:49:08?PM UTC-7, Kenneth Wolcott wrote:
> On Saturday, July 29, 2023 at 4:07:17?AM UTC-7, AdaMagica wrote:
> > > Powers_of_2 := Powers_of_2 * To_Big_Integer (2);
> > With the aspect Integer_Literal, also Powers_of_2 * 2 must work. The 
> > attributes Integer_Literal, Real_Literal, Put_Image make the new big 
> > numbers nearly work like numeric types (they are not). A difference: The 
> > range syntax for instance in loops A .. B is illegal.
> I understand that the range syntax in loops implies that the loop variable 
> is acting like an enumerated type which is not true for Big_Integers.
>
> What confused me is that I thought I had to convert the numeric literal 
> (I'll have to go back and look at the package spec again to get this 
> firmly understood.
>
> I have an another question about string slicing: I've tried (obviously 
> incorrectly) to use a variable is one of the slice integers. Can this be 
> done?
>
> Thanks,
> Ken

Apparently not :-(

gnatmake main.adb
gcc -c main.adb
main.adb:28:67: error: named parameters not permitted for attributes
     9 with Ada.Text_IO; use Ada.Text_IO;
    10 with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
    11 with Ada.Float_Text_IO; use Ada.Float_Text_IO;
    12 with Ada.Numerics.Elementary_Functions; use 
Ada.Numerics.Elementary_Functions;
    13 with Ada.Command_Line; use Ada.Command_Line;
    14
    15 procedure Main is
    16   Substr : String := Argument (1);
    17   Nth : Positive := Integer'Value (Argument (2));
    18   I, J : Natural;
    19   Temp : Float;
    20 begin
    21   I := 0;
    22   J := 0;
    23   loop
    24     I := I + 1;
    25     exit when I >= 10;
    26     Temp := 10.0 ** (log (2.0, 10.0) * Float (I));
    27     if I >= 4  then
    28       if (Float'Image (10.0 ** (log (2.0, 10.0) * Float (I)), Aft => 
0, Exp => 0) (1 .. Substr'Length) = Substr then
    29         J := J + 1;
    30         if J = Nth then
    31           Put (I, 0);
    32           New_Line;
    33           exit;
    34         end if;
    35       end if;
    36     end if;
    37   end loop;
    38 end Main;

Thanks,
Ken 


  reply	other threads:[~2023-07-30  4:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-27  5:26 When using the Ada Big_Numbers.Big_Integers package, can the To_String function output be sliced? Kenneth Wolcott
2023-07-27  8:53 ` Jeffrey R.Carter
2023-07-27 22:47   ` Kenneth Wolcott
2023-07-28 17:19     ` AdaMagica
2023-07-28 18:21     ` Simon Wright
2023-07-29  3:29       ` Kenneth Wolcott
2023-07-29 11:07       ` AdaMagica
2023-07-29 23:49         ` Kenneth Wolcott
2023-07-29 23:53           ` Kenneth Wolcott
2023-07-30  4:43             ` Randy Brukardt [this message]
2023-07-31 19:36               ` Kenneth Wolcott
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox