math exception handling
Posted: Mon Nov 17, 2003 1:21 am
Hi all,
I've been looking into the math side of newlisp (that's my current interest in it) but
I don't see specified how newlisp handles floating point overflow exceptions.
From nl-math.c addition (for example) is done by:
CELL * floatOp(CELL * params, int operand)
{
double number;
double result;
double fltNum;
long intNum;
params = getFloat(params, &result);
if(params == nilCell)
{
if(operand == OP_SUBTRACT)
result = - result;
}
while(params != nilCell)
{
params = getFloat(params, &number);
switch(operand)
{
case OP_ADD: result += number; break
and early in the file there seems to be a "do nothing" exception handling established (fair enough default) viz:
#ifdef __BORLANDC__
int _matherr(struct _exception *e) {return 0;};
#endif
Now - causing an addition overflow crashes newlisp eg:
C:\newlisp>newlisp
newLISP v7.3.3 Copyright (c) 2003 Lutz Mueller. All rights reserved.
> 1.7976931348623157E308
1.797693135e+308
> (add 1.7976931348623157E308 0.1e308)
C:\newlisp>
I don't know what happens on linux. Can math exceptions be caught/handled in win32 newlisp? Could it gracefully die with an
error message? I don't have documentation on how
Borlands BCC55 uses matherr.
Regards
Nigel
I've been looking into the math side of newlisp (that's my current interest in it) but
I don't see specified how newlisp handles floating point overflow exceptions.
From nl-math.c addition (for example) is done by:
CELL * floatOp(CELL * params, int operand)
{
double number;
double result;
double fltNum;
long intNum;
params = getFloat(params, &result);
if(params == nilCell)
{
if(operand == OP_SUBTRACT)
result = - result;
}
while(params != nilCell)
{
params = getFloat(params, &number);
switch(operand)
{
case OP_ADD: result += number; break
and early in the file there seems to be a "do nothing" exception handling established (fair enough default) viz:
#ifdef __BORLANDC__
int _matherr(struct _exception *e) {return 0;};
#endif
Now - causing an addition overflow crashes newlisp eg:
C:\newlisp>newlisp
newLISP v7.3.3 Copyright (c) 2003 Lutz Mueller. All rights reserved.
> 1.7976931348623157E308
1.797693135e+308
> (add 1.7976931348623157E308 0.1e308)
C:\newlisp>
I don't know what happens on linux. Can math exceptions be caught/handled in win32 newlisp? Could it gracefully die with an
error message? I don't have documentation on how
Borlands BCC55 uses matherr.
Regards
Nigel