procedure dec_bin(**a:real**); var wstr,mdstr:string;i,lng:integer;b,c,md:real; begin repeat **b:=a/2;** c:=frac(b); if c=0 then md:=0 else md:=1; str(md,mdstr); wstr:=concat(wstr,mdstr); **a:=trunc(b);** until a=1; wstr:=concat(wstr,'1'); lng:=length(wstr); for i:=lng downto 1 do binstr:=concat(binstr,wstr[i]); end; 

Entering 'a' with more than 10 digits gives the error:

Runtime Error: The value was unacceptably small or unacceptably large for an Int32.

  • Specify on which line the error occurs? - Kromster
  • An error occurs on the line a:=trunc(b) . - Brain Arsonist
  • That is, do you mean that b is outside the scope of the int32 type, or that the trunc function returns a variable to an integer type as a result of cutting the characters after the point? - Brain Arsonist
  • My b described as a real variable - Brain Arsonist
  • See help for Trunc in Pascal. In Delphi, this is exactly what happens ( the trunc function returns a variable to an integer type as a result of truncating the characters after the dot ), only in Delphi it is an int64. - Kromster

1 answer 1

a:=trunc(b); leads a number with a dot to a whole. By default, it seems to be an int32 (32-bit integer). In terms of meaning, int32 can only hold numbers from the -2³¹ range. + 2³¹-1.

You probably have b out of range, hence the error.