[vox-tech] help with signals and C

Mark K. Kim vox-tech@lists.lugod.org
Thu, 14 Mar 2002 09:24:06 -0800 (PST)


On Thu, 14 Mar 2002, Peter Jay Salzman wrote:

> yeah, i read about this in jeff's 1st link.  i'm not really doing much
> integer stuff, so it wasn't an issue and i didn't check it.  interesting
> that integer divide by zero gets caught!

In the x86 architecture, integer division by zero generates software
interrupt 0; that makes it easy to catch the problem:

   http://www.delorie.com/djgpp/doc/rbinter/id/06/0.html

I'm not sure about how the x86 interfaces with the FPU, so I couldn't tell
you why it doesn't get caught.  However:

   - Floating point division by zero is a well defined behavior.  Such
     an instruction shouldn't kill the program by default.

   - Integer division by zero should (in general) kill the program by
     default.

   - Therefore floating point division by zero and integer division by
     zero can't have the same default handler.

> > I'm not sure what kind of errors your program would have if it's not
> > generating "inf" or "nan".
==8<--
> example:
>
> temperature = 1.0
>
> trials          Energy per site
> 1,000          -2.000000
> 10,000         -1.998448
> 100,000        -1.997171
> 1,000,000      -1.997530
> 10,000,000     -1.997312           <-- very close
> 100,000,000   -14.163610           <-- very not correct

I have no idea what that means...  At a glance, it looks like a rounding
error to me...

> mark, did you mention arbitrary precision library?  just out of
> curiosity, what is it called?

I just mentioned it because there's one for Java so I figured there'd be
one for C and/or C++.  Doing a quick "The Big G" search yields GNU MP:

   http://swox.com/gmp/

-Mark

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