2005-07-30 21:37:29 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Author : philippe.billet@noos.fr
|
|
|
|
//
|
|
|
|
// Characteristic set function carac(x,a,b)
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "defs.h"
|
|
|
|
|
2006-09-20 18:09:25 +02:00
|
|
|
static int exp_flag;
|
|
|
|
|
2005-07-30 21:37:29 +02:00
|
|
|
void
|
|
|
|
eval_carac(void)
|
|
|
|
{
|
|
|
|
push(cadr(p1));
|
|
|
|
eval();
|
|
|
|
push(caddr(p1));
|
|
|
|
eval();
|
|
|
|
push(cadddr(p1));
|
|
|
|
eval();
|
|
|
|
carac();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
carac(void)
|
|
|
|
{
|
|
|
|
save();
|
2005-10-27 19:39:15 +02:00
|
|
|
yycarac();
|
2005-07-30 21:37:29 +02:00
|
|
|
restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
#define X p1
|
|
|
|
#define A p2
|
|
|
|
#define B p3
|
|
|
|
|
|
|
|
void
|
2005-10-27 19:39:15 +02:00
|
|
|
yycarac(void)
|
2005-07-30 21:37:29 +02:00
|
|
|
{
|
|
|
|
B = pop();
|
|
|
|
A = pop();
|
|
|
|
X = pop();
|
|
|
|
|
2005-08-06 22:57:37 +02:00
|
|
|
if (isdouble(X) && isdouble(A) && isdouble(B)) {
|
2005-07-30 21:37:29 +02:00
|
|
|
if (X->u.d > B->u.d && X->u.d < A->u.d)
|
|
|
|
{push_integer(1);
|
|
|
|
return;}
|
|
|
|
else
|
|
|
|
if (X->u.d == B->u.d || X->u.d == A->u.d)
|
|
|
|
{push_rational(1, 2);
|
|
|
|
return;}
|
|
|
|
else
|
|
|
|
{push_integer(0);
|
|
|
|
return;}
|
|
|
|
}
|
|
|
|
|
2005-08-06 22:57:37 +02:00
|
|
|
if (isrational(X) && isrational(A) && isrational(B)) {
|
2005-07-30 21:37:29 +02:00
|
|
|
if (MSIGN(msub(mmul(X->u.q.b,A->u.q.a),mmul(X->u.q.a,A->u.q.b))) == -1
|
|
|
|
&&
|
|
|
|
MSIGN(msub(mmul(X->u.q.a,B->u.q.b),mmul(X->u.q.b,B->u.q.a))) == -1)
|
|
|
|
{push_integer(1);
|
|
|
|
return;}
|
|
|
|
else
|
|
|
|
if (MZERO(msub(mmul(X->u.q.b,A->u.q.a),mmul(X->u.q.a,A->u.q.b)))
|
|
|
|
||
|
|
|
|
MZERO(msub(mmul(X->u.q.a,B->u.q.b),mmul(X->u.q.b,B->u.q.a))))
|
|
|
|
{push_rational(1, 2);
|
|
|
|
return;}
|
|
|
|
else
|
|
|
|
{push_integer(0);
|
|
|
|
return;}
|
|
|
|
}
|
|
|
|
|
2006-05-06 01:27:26 +02:00
|
|
|
if (exp_flag) {
|
2005-07-30 21:37:29 +02:00
|
|
|
push(X);
|
|
|
|
push_integer(-1);
|
|
|
|
push(A);
|
|
|
|
multiply();
|
|
|
|
add();
|
|
|
|
heaviside();
|
|
|
|
push(X);
|
|
|
|
push_integer(-1);
|
|
|
|
push(B);
|
|
|
|
multiply();
|
|
|
|
add();
|
|
|
|
heaviside();
|
|
|
|
push_integer(-1);
|
|
|
|
multiply();
|
|
|
|
add();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isnegativeterm(X)) {
|
|
|
|
push_symbol(CARAC);
|
|
|
|
push(X);
|
|
|
|
negate();
|
|
|
|
push(A);
|
|
|
|
push(B);
|
|
|
|
list(4);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
push_symbol(CARAC);
|
|
|
|
push(X);
|
|
|
|
push(A);
|
|
|
|
push(B);
|
|
|
|
list(4);
|
|
|
|
}
|
|
|
|
|
2007-05-08 16:57:30 +02:00
|
|
|
#if SELFTEST
|
|
|
|
|
2005-07-30 21:37:29 +02:00
|
|
|
static char *s[] = {
|
|
|
|
|
|
|
|
|
|
|
|
"carac(-2,-1,1)",
|
|
|
|
"0",
|
|
|
|
|
|
|
|
"carac(-1,-1,1)",
|
|
|
|
"1/2",
|
|
|
|
|
|
|
|
"carac(0,-1,1)",
|
|
|
|
"1",
|
|
|
|
|
|
|
|
"carac(1,-1,1)",
|
|
|
|
"1/2",
|
|
|
|
|
|
|
|
"carac(2,-1,1)",
|
|
|
|
"0",
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
test_carac(void)
|
|
|
|
{
|
|
|
|
test(__FILE__, s, sizeof s / sizeof (char *));
|
2005-07-31 18:39:53 +02:00
|
|
|
}
|
|
|
|
|
2007-05-08 16:57:30 +02:00
|
|
|
#endif
|