2005-07-30 21:37:29 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Author : philippe.billet@noos.fr
|
|
|
|
//
|
|
|
|
// sgn sign function
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
eval_sgn(void)
|
|
|
|
{
|
|
|
|
push(cadr(p1));
|
|
|
|
eval();
|
|
|
|
sgn();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sgn(void)
|
|
|
|
{
|
|
|
|
save();
|
2005-10-27 19:39:15 +02:00
|
|
|
yysgn();
|
2005-07-30 21:37:29 +02:00
|
|
|
restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
#define X p1
|
|
|
|
|
|
|
|
void
|
2005-10-27 19:39:15 +02:00
|
|
|
yysgn(void)
|
2005-07-30 21:37:29 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
X = pop();
|
|
|
|
|
|
|
|
|
2005-08-06 22:57:37 +02:00
|
|
|
if (isdouble(p1)) {
|
2005-07-30 21:37:29 +02:00
|
|
|
if (p1->u.d > 0)
|
|
|
|
{push_integer(1);
|
|
|
|
return;}
|
|
|
|
else
|
|
|
|
if (p1->u.d == 0)
|
|
|
|
{push_integer(1);
|
|
|
|
return;}
|
|
|
|
else
|
|
|
|
{push_integer(-1);
|
|
|
|
return;}
|
|
|
|
}
|
|
|
|
|
2005-08-06 22:57:37 +02:00
|
|
|
if (isrational(p1)) {
|
2005-07-30 21:37:29 +02:00
|
|
|
if (MSIGN(mmul(p1->u.q.a,p1->u.q.b)) == -1)
|
|
|
|
{push_integer(-1);
|
|
|
|
return;}
|
|
|
|
else
|
|
|
|
if (MZERO(mmul(p1->u.q.a,p1->u.q.b)))
|
|
|
|
{push_integer(0);
|
|
|
|
return;}
|
|
|
|
else
|
|
|
|
{push_integer(1);
|
|
|
|
return;}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iscomplexnumber(X)){
|
|
|
|
push_integer(-1);
|
|
|
|
push(X);
|
|
|
|
absval();
|
|
|
|
power();
|
|
|
|
push(X);
|
|
|
|
multiply();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isnegativeterm(X)) {
|
|
|
|
push_symbol(SGN);
|
|
|
|
push(X);
|
|
|
|
negate();
|
|
|
|
list(2);
|
|
|
|
push_integer(-1);
|
|
|
|
multiply();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* push_integer(2);
|
|
|
|
push(X);
|
|
|
|
heaviside();
|
|
|
|
multiply();
|
|
|
|
push_integer(-1);
|
|
|
|
add(); */
|
|
|
|
|
|
|
|
push_symbol(SGN);
|
|
|
|
push(X);
|
|
|
|
list(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *s[] = {
|
|
|
|
|
|
|
|
|
|
|
|
"sgn(-3)",
|
|
|
|
"-1",
|
|
|
|
|
|
|
|
|
|
|
|
"sgn(0)",
|
|
|
|
"0",
|
|
|
|
|
|
|
|
"sgn(3)",
|
|
|
|
"1",
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
test_sgn(void)
|
|
|
|
{
|
|
|
|
test(__FILE__, s, sizeof s / sizeof (char *));
|
|
|
|
}
|