[Lazarus] Large Integer errors

Mehmet Erol Sanliturk sanliturk at ttmail.com
Sun Feb 15 04:03:17 CET 2009


On Saturday 14 February 2009 12:56:50 pm Dave Coventry wrote:
> Yes, great, thanks.
>
> Would there be any error or would Lazarus just continue as if nothing
> had happened?
>
> 2009/2/14 Howard Page-Clark <hdpc at talktalk.net>:
> > On Sat, 14 Feb 2009 12:30:55 +0200
> >
> > Dave Coventry <dgcoventry at gmail.com> wrote:
> >> function mycalc( num1,num2: real):integer;
> >> begin
> >>   Result:=trunc(num1*num2);
> >> end;
> >>
> >> How can I protect from the product of the two numbers being too big?
> >>
> >> If it's too big I want to discard it anyway.
> >
> > function mycalc( num1,num2: real):integer;
> >  begin
> >   Result:=trunc(num1*num2);
> >  if result > maxint then result := 0;
> >  end;
> >
> > Would this do what you want?
> >
> >
> > Howard Page-Clark <hdpc at talktalk.net>
> > _______________________________________________
> > Lazarus mailing list
> > Lazarus at lazarus.freepascal.org
> > http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
>
> _______________________________________________
> Lazarus mailing list
> Lazarus at lazarus.freepascal.org
> http://www.lazarus.freepascal.org/mailman/listinfo/lazarus



My application is to use first REAL arithmetic :


Var V : Extended  ;
 or 
Var V : Real ; 
or 
Var V : Double ;

...

  V := num1 ;
  V := V * num2 ;

 If ( V < Your_Maximum_Allowed_Value )
Then Result := trunc ( num1 * num2 ) 
Else Message ... about overflow ...

If you compare run1 * run2 directly maxint ,
multiplication may give overflow when result of multiplication is 
theoretically large than maxint .


Thank you very much .

Mehmet Erol Sanliturk


























More information about the Lazarus mailing list