From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: From_string(Arg : String) return Big_Integer
Date: Sun, 10 Jan 2021 17:02:59 +0100 [thread overview]
Message-ID: <rtf8fh$1mmv$1@gioia.aioe.org> (raw)
In-Reply-To: 5ffb21c8$0$21590$426a74cc@news.free.fr
On 2021-01-10 16:48, DrPi wrote:
> So either :
>
> for C of Str loop
> Num := (Num * 10) + Character'Pos (C) - Character'Pos ('0');
> end loop;
>
> or :
>
> for Idx in Str'Range loop
> Num := (Num * 10) + Character'Pos (Str(Idx)) - Character'Pos
> ('0');
> end loop;
Just for fun:
subtype Digit is Character range '0'..'9';
Encode : constant array (Digit) of Integer := (0,1,2,3,4,5,6,7,8,9);
for ... loop
Num := Num * 10 + Encode (C);
>> - It does not handle overflow;
> It handles overflow.
Only if Constraint_Error must be the result.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2021-01-10 16:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-09 15:16 From_string(Arg : String) return Big_Integer soren rundgren
2021-01-09 17:00 ` AdaMagica
2021-01-09 20:09 ` soren rundgren
2021-01-09 20:09 ` soren rundgren
2021-01-09 20:11 ` soren rundgren
2021-01-09 22:13 ` DrPi
2021-01-09 23:40 ` Jeffrey R. Carter
2021-01-10 9:46 ` Dmitry A. Kazakov
2021-01-10 15:48 ` DrPi
2021-01-10 16:02 ` Dmitry A. Kazakov [this message]
2021-01-10 16:33 ` DrPi
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox