l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
August 5: Social gathering
Next Installfest:
TBD
Latest News:
Jul. 4: July, August and September: Security, Photography and Programming for Kids
Page last updated:
2001 Dec 30 17:02

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] detecting overflows
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] detecting overflows



Well, SIGFPE is floating point exception... we're trying to detect
overflow, and detecting floating point overflow is easy -- you just get
infinity, a valid floating point value.

-Mark

On Mon, 12 Mar 2001, Bill Broadley wrote:

> I'd suggesting checking out sigaddset, and the SIGFPE signal.
> 
> Install your own signal handler and do whatever you want when you
> detect a SIGFPE.  I believe SIGFPE includes underflow, overflow, and
> divide by zero, not sure though.
> 
> On Mon, Mar 12, 2001 at 10:08:37AM -0800, Peter Jay Salzman wrote:
> > dear all,
> > 
> > i have code which looks like:
> > 
> >    long double dr;
> >    long double dt;
> >    long double rend;
> >    long double ratio;
> >    long int    N;
> >    long unsigned int max_tstep;
> > 
> >    ratio      = 2.0L;
> >    N          = 800;
> >    dr         = rend / ((long double)N - 1.0L);
> >    dt         = ratio*pow(dr, 2.0L);
> > 
> >    max_tstep  = (long unsigned int) ceil(endtime / dt);
> > 
> > sometimes ceil(endtime / dt) is very large, like 2.10944e+85.  this is too
> > large even for a long long int.  max_tstep overflows.
> > 
> > sometimes i don't catch the overflow, and my program can run for a long
> > time, producing garbage.
> > 
> > is there some kind of flag that i can check that gets raised when a
> > calculation overflows?   i have many such calculations (which are performed
> > once at the beginning, so i'm not worried about performance penalty).
> > 
> > i guess i can take a look at limit.h to and compare the maximum long
> > unsigned int to the value of endtime / dt, but i'd prefer a different
> > solution if one exists.  surely there's got to be SOME way of detecting this
> > kind of error?
> > 
> > i care not for portability.  it's running on a bunch of pentium II, III and
> > athlon class machines and nothing else.   gcc extensions are welcome
> > (although i took a look and didn't see anything immediately helpful).
> > 
> > the problem is fairly pernicious.  normally i would rescale variables, but
> > for this particular problem, a rescaling simply shifts the problem from one
> > variable to another.
> > 
> > thanks!
> > pete
> > 
> > -- 
> > "Coffee... I've conquered the Borg on coffee!"               p@dirac.org
> >        -- Kathryn Janeway on the virtues of coffee           www.dirac.org/p
> 

---
Mark K. Kim
http://www.cbreak.org/mark/
PGP key available upon request.


LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Sunset Systems
Who graciously hosts our website & mailing lists!