Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Disc space -- the final frontier!


devel / comp.lang.ada / Re: GNAT Community 2020 (20200818-93): Big_Integer

SubjectAuthor
* GNAT Community 2020 (20200818-93): Big_IntegerFrank Jørgen Jørgensen
+- Re: GNAT Community 2020 (20200818-93): Big_IntegerDmitry A. Kazakov
`* Re: GNAT Community 2020 (20200818-93): Big_IntegerSimon Wright
 `- Re: GNAT Community 2020 (20200818-93): Big_IntegerRandy Brukardt

1
GNAT Community 2020 (20200818-93): Big_Integer

<55561d4b-8288-4770-a7b5-681567752ab0n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9789&group=comp.lang.ada#9789

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ac8:5948:0:b0:401:e192:fc61 with SMTP id 8-20020ac85948000000b00401e192fc61mr11773qtz.7.1688153303278;
Fri, 30 Jun 2023 12:28:23 -0700 (PDT)
X-Received: by 2002:a17:90a:4205:b0:262:f758:9ad4 with SMTP id
o5-20020a17090a420500b00262f7589ad4mr2180653pjg.1.1688153302720; Fri, 30 Jun
2023 12:28:22 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Fri, 30 Jun 2023 12:28:22 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=84.202.177.60; posting-account=1IjL1QoAAACctxlLLMeV34DU0ik-1SwI
NNTP-Posting-Host: 84.202.177.60
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <55561d4b-8288-4770-a7b5-681567752ab0n@googlegroups.com>
Subject: GNAT Community 2020 (20200818-93): Big_Integer
From: fjj@itema.no (Frank Jørgen Jørgensen)
Injection-Date: Fri, 30 Jun 2023 19:28:23 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2120
 by: Frank Jørgen Jørge - Fri, 30 Jun 2023 19:28 UTC

Hi

I'm running the below program with GNAT Community 2020 (20200818-93)
on Windows 11 Home.
I have some problems trying to save big numbers to a file - so I noticed this behaviour:
If I open Test.dat in Visual Studio Hex editor, it seems like this program saves this big number with a different bit pattern each time.
Is that as expected?
I do have some problems reading back the big numbers in my real code.
When I compile I get the warning: "Ada.Numerics.Big_Numbers.Big_Integers" is an Ada 202x unit.

Frank

--
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
with Ada.Numerics.Big_Numbers.Big_Integers;

procedure Test is

B1 : Ada.Numerics.Big_Numbers.Big_Integers.Big_Integer;
F1 : File_Type;
S1 : Stream_Access;
begin
B1 := 1;

Ada.Streams.Stream_IO.Create (F1, Out_File, "Test.dat");
S1 := Ada.Streams.Stream_IO.Stream (F1);
Ada.Numerics.Big_Numbers.Big_Integers.Big_Integer'Write(S1, B1);
Ada.Numerics.Big_Numbers.Big_Integers.Big_Integer'Output(S1, B1);
Ada.Streams.Stream_IO.Close (F1);
end Test;

Re: GNAT Community 2020 (20200818-93): Big_Integer

<u7ng5u$2kjcv$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9790&group=comp.lang.ada#9790

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: GNAT Community 2020 (20200818-93): Big_Integer
Date: Fri, 30 Jun 2023 23:07:10 +0200
Organization: A noiseless patient Spider
Lines: 162
Message-ID: <u7ng5u$2kjcv$1@dont-email.me>
References: <55561d4b-8288-4770-a7b5-681567752ab0n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 30 Jun 2023 21:07:10 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cd87d6d5da359623298485c320aae58c";
logging-data="2772383"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18WpkNmgJl3DtcNi1MwaGiwmZt51S8WnhA="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.12.0
Cancel-Lock: sha1:yX/+5xbDUfGiCkXJnbHagKd53LA=
In-Reply-To: <55561d4b-8288-4770-a7b5-681567752ab0n@googlegroups.com>
Content-Language: en-US
 by: Dmitry A. Kazakov - Fri, 30 Jun 2023 21:07 UTC

On 2023-06-30 21:28, Frank Jørgen Jørgensen wrote:

> I'm running the below program with GNAT Community 2020 (20200818-93)
> on Windows 11 Home.
> I have some problems trying to save big numbers to a file - so I noticed this behaviour:
> If I open Test.dat in Visual Studio Hex editor, it seems like this program saves this big number with a different bit pattern each time.
> Is that as expected?
> I do have some problems reading back the big numbers in my real code.
> When I compile I get the warning: "Ada.Numerics.Big_Numbers.Big_Integers" is an Ada 202x unit.
>
> --
> with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
> with Ada.Numerics.Big_Numbers.Big_Integers;
>
> procedure Test is
>
> B1 : Ada.Numerics.Big_Numbers.Big_Integers.Big_Integer;
> F1 : File_Type;
> S1 : Stream_Access;
> begin
> B1 := 1;
>
> Ada.Streams.Stream_IO.Create (F1, Out_File, "Test.dat");
> S1 := Ada.Streams.Stream_IO.Stream (F1);
> Ada.Numerics.Big_Numbers.Big_Integers.Big_Integer'Write(S1, B1);
> Ada.Numerics.Big_Numbers.Big_Integers.Big_Integer'Output(S1, B1);
> Ada.Streams.Stream_IO.Close (F1);
> end Test;

As a general rule, you should never use predefined implementations of
stream attributes except for Stream_Element or Character. Anything else
you must always override or else not use.

If you want to serialize signed integers use some portable format for
it. E.g. a chained encoding.

Here is a test program for a straightforward implementation of chained
store/restore:
-------------------------
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
with Ada.Numerics.Big_Numbers.Big_Integers;
with Ada.Exceptions;
with Ada.IO_Exceptions;

procedure Test is

use Ada.Streams;
use Ada.Numerics.Big_Numbers.Big_Integers;
use Ada.Exceptions;
use Ada.Streams.Stream_IO;

Two : constant Big_Integer := To_Big_Integer (2);

package Conversions is new Unsigned_Conversions (Stream_Element);
use Conversions;

function Get
( Stream : in out Root_Stream_Type'Class
) return Big_Integer is
Result : Big_Integer;
Power : Natural := 6;
Negative : Boolean;
Buffer : Stream_Element_Array (1..1);
Last : Stream_Element_Offset;
This : Stream_Element renames Buffer (1);
begin
Stream.Read (Buffer, Last);
if Last /= 1 then
raise End_Error;
end if;
Result := To_Big_Integer ((This and 2#0111_1110#) / 2);
Negative := 0 /= (This and 1);
if 0 = (This and 16#80#) then
if Negative then
return -Result - 1;
else
return Result;
end if;
end if;
loop
Stream.Read (Buffer, Last);
if Last /= 1 then
raise End_Error;
end if;
Result := Result +
Two**Power * To_Big_Integer (This and 16#7F#);
if 0 = (This and 16#80#) then
if Negative then
return -Result - 1;
else
return Result;
end if;
end if;
Power := Power + 7;
end loop;
end Get;

procedure Put
( Stream : in out Root_Stream_Type'Class;
Value : Big_Integer
) is
Item : Big_Integer := Value;
Buffer : Stream_Element_Array (1..1);
This : Stream_Element renames Buffer (1);
begin
if Item >= 0 then
Item := Value;
This := From_Big_Integer (Item mod (16#40#)) * 2;
else
Item := -(Value + 1);
This := From_Big_Integer (Item mod (16#40#)) * 2 + 1;
end if;
Item := Item / 16#40#;
if Item = 0 then
Stream.Write (Buffer);
return;
end if;
This := This or 16#80#;
Stream.Write (Buffer);
loop
This := From_Big_Integer (Item mod 16#80#) or 16#80#;
Item := Item / 16#80#;
if Item = 0 then
This := This and 16#7F#;
Stream.Write (Buffer);
return;
end if;
Stream.Write (Buffer);
end loop;
end Put;

F : File_Type;
begin
Create (F, Out_File, "Test.dat");
for I in -1_000_000..1_000_000 loop
Put (Stream (F).all, To_Big_Integer (I));
end loop;
Close (F);
Open (F, In_File, "Test.dat");
for I in -1_000_000..1_000_000 loop
declare
Value : constant Big_Integer := Get (Stream (F).all);
begin
if Value /= To_Big_Integer (I) then
raise Data_Error;
end if;
end;
end loop;
Close (F);
end Test;
-------------------------
The above could be optimized to work with buffers rather than
reading/writing stream octets one by one. It is a long story, but
normally you would implement some data blocks with the length count on
top of the stream in order to avoid inefficient octet by octet reading
and add an error correction layer.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: GNAT Community 2020 (20200818-93): Big_Integer

<lyr0prq19e.fsf@pushface.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9792&group=comp.lang.ada#9792

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: simon@pushface.org (Simon Wright)
Newsgroups: comp.lang.ada
Subject: Re: GNAT Community 2020 (20200818-93): Big_Integer
Date: Sat, 01 Jul 2023 13:12:13 +0100
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <lyr0prq19e.fsf@pushface.org>
References: <55561d4b-8288-4770-a7b5-681567752ab0n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="62632d92463326eb3c9a5ec09a14c534";
logging-data="3078837"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19hzPDrI1z3IJatS52tzfuzj4f5NoFbkh8="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (darwin)
Cancel-Lock: sha1:XcRzMahGP20uATGNBnIE4SHwzdU=
sha1:eXVUtzhd4D7STylEyEU60aXYcF4=
 by: Simon Wright - Sat, 1 Jul 2023 12:12 UTC

Frank Jørgen Jørgensen <fjj@itema.no> writes:

> I'm running the below program with GNAT Community 2020 (20200818-93)
> on Windows 11 Home.
> I have some problems trying to save big numbers to a file - so I
> noticed this behaviour:
> If I open Test.dat in Visual Studio Hex editor, it seems like this
> program saves this big number with a different bit pattern each time.
> Is that as expected?
> I do have some problems reading back the big numbers in my real code.

Looking at the source for Big_Integer[1] I see no trace of streaming
support; what you got streamed was the address of some allocated data
used under the hood to contain the big integer.

I don't know whether the ARM requires/expects Big_Integer to be
streamable, but I think you had every reason to expect it!

[1] https://github.com/gcc-mirror/gcc/blob/7e904d6c7f252ee947c237ed32dd43b2c248384d/gcc/ada/libgnat/a-nbnbin.ads#L171

Re: GNAT Community 2020 (20200818-93): Big_Integer

<u8ajcf$1kk9n$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9829&group=comp.lang.ada#9829

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: randy@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: GNAT Community 2020 (20200818-93): Big_Integer
Date: Fri, 7 Jul 2023 21:58:35 -0500
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <u8ajcf$1kk9n$1@dont-email.me>
References: <55561d4b-8288-4770-a7b5-681567752ab0n@googlegroups.com> <lyr0prq19e.fsf@pushface.org>
Injection-Date: Sat, 8 Jul 2023 02:58:24 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c22dff3d0c5d9d50aab05dbe8a9b8b51";
logging-data="1724727"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ehJIey5f8W13MQep7fExIlvZwp1ZqBrk="
Cancel-Lock: sha1:zoIIuoaaAPsLB5NSNMLavcxI4Mk=
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
X-RFC2646: Format=Flowed; Original
X-Priority: 3
 by: Randy Brukardt - Sat, 8 Jul 2023 02:58 UTC

"Simon Wright" <simon@pushface.org> wrote in message
news:lyr0prq19e.fsf@pushface.org...
....
> I don't know whether the ARM requires/expects Big_Integer to be
> streamable, but I think you had every reason to expect it!

See 13.13.1(54/1):

For every subtype S of a language-defined nonlimited specific type T, the
output generated by S'Output or S'Write shall be readable by S'Input or
S'Read, respectively. This rule applies across partitions if the
implementation conforms to the Distributed Systems Annex.

Ada.Numerics.Big_Numbers.Big_Integers.Big_integer surely is a
language-defined nonlimited specific type, so the above applies. Streaming
should work, if it doesn't, that's a bug.

Randy.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor