How can I compare very large integers written in a file in Free Pascal?

How can I compare very large integers written in a file in Free Pascal? Let's say we have some number of numbers written to the file. We will separate them using EOF. End of line via EOL. Then how do we compare these numbers? Well, for clarity, let's write them down in descending order. Throw in ideas for implementation, and if there are still some scripts, it will be generally cool. I want to deal with these xD files. I have such an idea (but it is not implemented well). If we we write the first number in memory as an array of char. Let the first element be a[x] and the last a[z] of this number. Remember x and z: a:=x, b:=z.We read the second number, let the first element be a[x+1], and the second element be a[y] (x+1, since eof also takes up space). If z-xy-x-1, then we do nothing. But it turns out that it is always necessary to compare each element of the arrays, since there can be numbers 001 and 2, and my first comparison will already be an error.
Here I think so to compare, just need to come up with, so that at the beginning of the number, zeros are discarded. Is there any better way to describe it?

 x := 1;
   Reset(File1);
   While Not eof(File1) do
   Begin
      Read(File1, num[i]);
      Inc(i)
   End;
   z := i;
   j := z + 1;
   While Not eof(File1) do
   Begin
      Read(File1, num[j]);
      Inc(j)
   End;
   y := j;
   If j > i Then a := 1 Else If j = i Then
   Begin
      While z <> x do
      Begin
         If  Ord(num[j]) > Ord(num[i]) Then a := 1 Else If Ord(num[j]) < Ord(num[i]) Then a := 0;
         Dec(j);
         Dec(i)
      End;
   End Else a := 0;
   If a = 1 Then
   Begin
      x := z+1;
      z := y
   End;   
Author: Даниил Немов, 2017-10-20

1 answers

The sequence of actions for comparing large numbers that do not fit in longint:

  1. Write 2 numbers in two lines.

  2. Check the first characters for signs. If, for example, the first character of the first number is a minus, and the second is a digit, then the second number is greater.

  3. Check each row for insignificant zeros, find the index of the first occurrence of a number other than 0

  4. Check the dimensions of two rows if some of the strings have a larger size, so this number is larger and the algorithm ends at this step (taking into account the third step).

  5. Check the first characters, starting with the index of step 3 in two lines (converting them to a numeric format from the ASCIII table), if any of these numbers turns out to be large, then it turns out to be large and the algorithm ends at this step.

  6. This reconciliation is carried out with each up to the last element.

 2
Author: Санаев, 2018-04-19 23:41:50