Alan,
It has worked for me in the past... you could try out a test app. I
suspect it does not work for floating point overflow which always
generates an exception. You may also have to retype some of the
variables to enforce the overflow check. If you mix types (even
when it is an untyped constant), Delphi helpfully does conversions
to the largest operand before doing the operations.
Subject: RE: [DUG] Check for overflows in arithmetic operations?
Date sent: Thu, 24 Feb 2005 13:11:52 +1300
From: "Allan, Samuel" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>,
"NZ Borland Developers Group - Delphi List" <[email protected]>
Send reply to: NZ Borland Developers Group - Delphi List
<[email protected]>
<mailto:[EMAIL PROTECTED]>
<mailto:[EMAIL PROTECTED]>
> Thanks, but this does not seem to work. I have allready tried both, and
> I am happily getting negative results from my code. I assume that
> negative numbers mean it has overflowed, since all my answers should be
> positive.
>
> >From the help as I interpret it, {$Q+} only applies to a specific set of
> methods, but not to the multiplication operator.
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> On Behalf Of Rohit Gupta
> Sent: Thursday, February 24 2005 1:31 p.m.
> To: NZ Borland Developers Group - Delphi List
> Subject: Re: [DUG] Check for overflows in arithmetic operations?
>
>
> $R+ for range checking
> $Q+ For Integer overflow
>
> Date sent: Thu, 24 Feb 2005 11:51:31 +1300
> From: "Allan, Samuel" <[EMAIL PROTECTED]>
> To: <[email protected]>
> Subject: [DUG] Check for overflows in arithmetic
> operations?
> Send reply to: NZ Borland Developers Group - Delphi List
> <[email protected]>
> <mailto:[EMAIL PROTECTED]>
> <mailto:[EMAIL PROTECTED]>
>
> > Hi,
> >
> > I have some code that does integer maths. In the unlikely but possible
> > event that numbers large enough to cause overflows get put into it, I
> > would like to raise an exception or something. I do not yet know how
> to
> > detect if numbers are large enough. So I would like to know if it is
> > possible to get Delphi to detect an overflow.
> >
> > I can use 64 bit variables, but because I am calculating factorials it
> > is still easy to overflow them.
> >
> > I would like to know if my results are accurate or not.
> >
> > Thanks,
> > Samuel
> >
> > _______________________________________________
> > Delphi mailing list
> > [email protected]
> > http://ns3.123.co.nz/mailman/listinfo/delphi
> >
>
> Regards
>
> Rohit
>
> ======================================================================
> CFL - Computer Fanatics Ltd. 21 Barry's Point Road, AKL, New Zealand
> PH (649) 489-2280
> FX (649) 489-2290
> email [EMAIL PROTECTED] or [EMAIL PROTECTED]
> ======================================================================
>
>
> _______________________________________________
> Delphi mailing list
> [email protected]
> http://ns3.123.co.nz/mailman/listinfo/delphi
>
> _______________________________________________
> Delphi mailing list
> [email protected]
> http://ns3.123.co.nz/mailman/listinfo/delphi
>
Regards
Rohit
======================================================================
CFL - Computer Fanatics Ltd. 21 Barry's Point Road, AKL, New Zealand
PH (649) 489-2280
FX (649) 489-2290
email [EMAIL PROTECTED] or [EMAIL PROTECTED]
======================================================================
_______________________________________________
Delphi mailing list
[email protected]
http://ns3.123.co.nz/mailman/listinfo/delphi