comp.lang.ada
 help / color / mirror / Atom feed
From: DrPi <314@drpi.fr>
Subject: Re: From_string(Arg : String) return Big_Integer
Date: Sun, 10 Jan 2021 17:33:48 +0100	[thread overview]
Message-ID: <5ffb2c6d$0$13561$426a74cc@news.free.fr> (raw)
In-Reply-To: <rtf8fh$1mmv$1@gioia.aioe.org>

Le 10/01/2021 à 17:02, Dmitry A. Kazakov a écrit :
> 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);
> 
Nice one !

>>> - It does not handle overflow;
>> It handles overflow.
> 
> Only if Constraint_Error must be the result.
> 
Right.

      reply	other threads:[~2021-01-10 16:33 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
2021-01-10 16:33             ` DrPi [this message]
replies disabled

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