Search code examples
roundingpascalfreepascalint64

I need to work with round or trunc functions in FreePascal with very big numbers(such as INT64)


var a,c,i,y,k:cardinal;
    z:real;
    check:boolean;
    repet:array[1..1000] of cardinal;
    tripet:array[1..1000,1..2] of real;
begin
read(c);
i:=1;
for a:=1 to (c) do
  begin
    z:= sqrt(c*c-a*a);
    if (c=round(z)) or (round(z)=0) then continue;
    if z=round(z) then
      begin
        check:=false;
        for k:=1 to i do if repet[k]=z then check:=true;
        if (check) then continue;
        tripet[i][1]:=a;
        tripet[i][2]:=z;
        repet[i]:=a;
        i:=i+1;
      end;
  end;
if i=1 then write('Nope');
for y:=1 to (i-1) do writeln(tripet[y][1]:0:0,' ',tripet[y][2]:0:0);
end.

The problem is in round(z) which bring too large z number.It needs Int32 type.

But I need bigger number:for istance number can between 1 and 10^12

How can i solve it in?


Solution

  • You use cardinal which is a 32-bit type, and probably a round to match is found. Try to either use 64-bit types or use int64(c)=round(z) to force 64-bit round?