version 1.3, 2003/02/14 22:29:09 |
version 1.8, 2018/03/29 01:32:52 |
|
|
/* |
/* |
* $OpenXM: OpenXM_contrib2/asir2000/engine/p-itv.c,v 1.2 2002/01/08 04:14:37 kondoh Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/engine/p-itv.c,v 1.7 2009/03/27 14:42:29 ohara Exp $ |
*/ |
*/ |
#if defined(INTERVAL) |
#if defined(INTERVAL) |
#include "ca.h" |
#include "ca.h" |
Line 12 extern int zerorewrite; |
|
Line 12 extern int zerorewrite; |
|
|
|
void itvtois(Itv a, Num *inf, Num *sup) |
void itvtois(Itv a, Num *inf, Num *sup) |
{ |
{ |
if ( !a ) |
if ( !a ) |
*inf = *sup = (Num)0; |
*inf = *sup = (Num)0; |
else if ( NID(a) <= N_B ) { |
else if ( NID(a) <= N_B ) { |
*inf = (Num)a; *sup = (Num)a; |
*inf = (Num)a; *sup = (Num)a; |
} else { |
} else { |
*inf = INF(a); |
*inf = INF(a); |
*sup = SUP(a); |
*sup = SUP(a); |
} |
} |
} |
} |
|
|
void istoitv(Num inf, Num sup, Itv *rp) |
void istoitv(Num inf, Num sup, Itv *rp) |
{ |
{ |
Num i, s; |
Num i, s; |
Itv c; |
Itv c; |
int type=0; |
int type=0; |
|
|
if ( !inf && !sup ) { |
if ( !inf && !sup ) { |
*rp = 0; |
*rp = 0; |
return; |
return; |
} |
} |
if ( !sup ) { |
if ( !sup ) { |
s = 0; |
s = 0; |
} |
} |
else if ( NID( sup )==N_B ) { |
else if ( NID( sup )==N_B ) { |
type = 1; |
type = 1; |
ToBf(sup, (BF *)&s); |
ToBf(sup, (BF *)&s); |
} else { |
} else { |
s = sup; |
s = sup; |
} |
} |
if ( !inf ) { |
if ( !inf ) { |
i = 0; |
i = 0; |
} |
} |
else if ( NID( inf )==N_B ) { |
else if ( NID( inf )==N_B ) { |
type = 1; |
type = 1; |
ToBf(inf, (BF *)&i); |
ToBf(inf, (BF *)&i); |
} else { |
} else { |
i = inf; |
i = inf; |
} |
} |
if ( type ) |
if ( type ) { |
NEWIntervalBigFloat((IntervalBigFloat)c); |
// NEWIntervalBigFloat((IntervalBigFloat)c); |
else |
c=MALLOC(sizeof(struct oIntervalBigFloat)); |
NEWItvP(c); |
OID(c)=O_N; |
|
NID(c)=N_IntervalBigFloat; |
|
} else |
|
NEWItvP(c); |
|
|
if ( compnum(0,i,s) >= 0 ) { |
if ( compnum(0,i,s) >= 0 ) { |
INF(c) = s; SUP(c) = i; |
INF(c) = s; SUP(c) = i; |
} else { |
} else { |
INF(c) = i; SUP(c) = s; |
INF(c) = i; SUP(c) = s; |
} |
} |
|
|
if (zerorewrite) |
if (zerorewrite) |
if ( initvp(0,c) ) { |
if ( initvp(0,c) ) { |
*rp = 0; |
*rp = 0; |
return; |
return; |
} |
} |
*rp = c; |
*rp = c; |
} |
} |
|
|
void additvp(Itv a, Itv b, Itv *c) |
void additvp(Itv a, Itv b, Itv *c) |
{ |
{ |
Num ai,as,bi,bs; |
Num ai,as,bi,bs; |
Num inf,sup; |
Num inf,sup; |
|
|
if ( !a ) |
if ( !a ) |
*c = b; |
*c = b; |
else if ( !b ) |
else if ( !b ) |
*c = a; |
*c = a; |
else if ( (NID(a) <= N_B) && (NID(b) <= N_B ) ) |
else if ( (NID(a) <= N_B) && (NID(b) <= N_B ) ) |
addnum(0,(Num)a,(Num)b,(Num *)c); |
addnum(0,(Num)a,(Num)b,(Num *)c); |
else if ( (NID(a) == N_IP) && (NID(b) == N_R ) |
else if ( (NID(a) == N_IP) && (NID(b) == N_R ) |
||(NID(a) == N_R ) && (NID(b) == N_IP) ) |
||(NID(a) == N_R ) && (NID(b) == N_IP) ) |
additvd((Num)a,(Num)b,(IntervalDouble *)c); |
additvd((Num)a,(Num)b,(IntervalDouble *)c); |
else { |
else { |
itvtois(a,&ai,&as); |
itvtois(a,&ai,&as); |
itvtois(b,&bi,&bs); |
itvtois(b,&bi,&bs); |
addnum(0,ai,bi,&inf); |
addnum(0,ai,bi,&inf); |
addnum(0,as,bs,&sup); |
addnum(0,as,bs,&sup); |
istoitv(inf,sup,c); |
istoitv(inf,sup,c); |
} |
} |
} |
} |
|
|
void subitvp(Itv a, Itv b, Itv *c) |
void subitvp(Itv a, Itv b, Itv *c) |
{ |
{ |
Num ai,as,bi,bs; |
Num ai,as,bi,bs; |
Num inf,sup; |
Num inf,sup; |
|
|
if ( !a ) |
if ( !a ) |
chsgnnum((Num)b,(Num *)c); |
chsgnnum((Num)b,(Num *)c); |
else if ( !b ) |
else if ( !b ) |
*c = a; |
*c = a; |
else if ( (NID(a) <= N_B) && (NID(b) <= N_B ) ) |
else if ( (NID(a) <= N_B) && (NID(b) <= N_B ) ) |
subnum(0,(Num)a,(Num)b,(Num *)c); |
subnum(0,(Num)a,(Num)b,(Num *)c); |
else if ( (NID(a) == N_IP) && (NID(b) == N_R ) |
else if ( (NID(a) == N_IP) && (NID(b) == N_R ) |
||(NID(a) == N_R ) && (NID(b) == N_IP) ) |
||(NID(a) == N_R ) && (NID(b) == N_IP) ) |
subitvd((Num)a,(Num)b,(IntervalDouble *)c); |
subitvd((Num)a,(Num)b,(IntervalDouble *)c); |
else { |
else { |
itvtois(a,&ai,&as); |
itvtois(a,&ai,&as); |
itvtois(b,&bi,&bs); |
itvtois(b,&bi,&bs); |
subnum(0,ai,bs,&inf); |
subnum(0,ai,bs,&inf); |
subnum(0,as,bi,&sup); |
subnum(0,as,bi,&sup); |
istoitv(inf,sup,c); |
istoitv(inf,sup,c); |
} |
} |
} |
} |
|
|
void mulitvp(Itv a, Itv b, Itv *c) |
void mulitvp(Itv a, Itv b, Itv *c) |
{ |
{ |
Num ai,as,bi,bs,a1,a2,b1,b2,c1,c2,p,t; |
Num ai,as,bi,bs,a1,a2,b1,b2,c1,c2,p,t; |
int ba,bb; |
int ba,bb; |
|
|
if ( !a || !b ) |
if ( !a || !b ) |
*c = 0; |
*c = 0; |
else if ( (NID(a) <= N_B) && (NID(b) <= N_B ) ) |
else if ( (NID(a) <= N_B) && (NID(b) <= N_B ) ) |
mulnum(0,(Num)a,(Num)b,(Num *)c); |
mulnum(0,(Num)a,(Num)b,(Num *)c); |
else if ( (NID(a) == N_IP) && (NID(b) == N_R ) |
else if ( (NID(a) == N_IP) && (NID(b) == N_R ) |
||(NID(a) == N_R ) && (NID(b) == N_IP) ) |
||(NID(a) == N_R ) && (NID(b) == N_IP) ) |
mulitvd((Num)a,(Num)b,(IntervalDouble *)c); |
mulitvd((Num)a,(Num)b,(IntervalDouble *)c); |
else { |
else { |
itvtois(a,&ai,&as); |
itvtois(a,&ai,&as); |
itvtois(b,&bi,&bs); |
itvtois(b,&bi,&bs); |
chsgnnum(as,&a2); |
chsgnnum(as,&a2); |
chsgnnum(bs,&b2); |
chsgnnum(bs,&b2); |
if ( ba = (compnum(0,0,a2) > 0) ) { |
if ( ba = (compnum(0,0,a2) > 0) ) { |
a1 = ai; |
a1 = ai; |
} else { |
} else { |
a1 = a2; |
a1 = a2; |
a2 = ai; |
a2 = ai; |
} |
} |
if ( bb = (compnum(0,0,b2) > 0) ) { |
if ( bb = (compnum(0,0,b2) > 0) ) { |
b1 = bi; |
b1 = bi; |
} else { |
} else { |
b1 = b2; |
b1 = b2; |
b2 = bi; |
b2 = bi; |
} |
} |
mulnum(0,a2,b2,&t); |
mulnum(0,a2,b2,&t); |
subnum(0,0,t,&c2); |
subnum(0,0,t,&c2); |
if ( compnum(0,0,b1) > 0 ) { |
if ( compnum(0,0,b1) > 0 ) { |
mulnum(0,a2,b1,&t); |
mulnum(0,a2,b1,&t); |
subnum(0,0,t,&c1); |
subnum(0,0,t,&c1); |
if ( compnum(0,0,a1) > 0 ) { |
if ( compnum(0,0,a1) > 0 ) { |
mulnum(0,a1,b2,&t); |
mulnum(0,a1,b2,&t); |
subnum(0,0,t,&p); |
subnum(0,0,t,&p); |
if ( compnum(0,c1,p) > 0 ) c1 = p; |
if ( compnum(0,c1,p) > 0 ) c1 = p; |
mulnum(0,a1,b1,&t); |
mulnum(0,a1,b1,&t); |
subnum(0,0,t,&p); |
subnum(0,0,t,&p); |
if ( compnum(0,c2,p) > 0 ) c2 = p; |
if ( compnum(0,c2,p) > 0 ) c2 = p; |
} |
} |
} else { |
} else { |
if ( compnum(0,0,a1) > 0 ) { |
if ( compnum(0,0,a1) > 0 ) { |
mulnum(0,a1,b2,&t); |
mulnum(0,a1,b2,&t); |
subnum(0,0,t,&c1); |
subnum(0,0,t,&c1); |
} else { |
} else { |
mulnum(0,a1,b1,&c1); |
mulnum(0,a1,b1,&c1); |
} |
} |
} |
} |
if ( ba == bb ) { |
if ( ba == bb ) { |
subnum(0,0,c2,&t); |
subnum(0,0,c2,&t); |
istoitv(c1,t,c); |
istoitv(c1,t,c); |
} else { |
} else { |
subnum(0,0,c1,&t); |
subnum(0,0,c1,&t); |
istoitv(c2,t,c); |
istoitv(c2,t,c); |
} |
} |
} |
} |
} |
} |
|
|
int initvp(Num a, Itv b) |
int initvp(Num a, Itv b) |
{ |
{ |
Num inf, sup; |
Num inf, sup; |
|
|
itvtois(b, &inf, &sup); |
itvtois(b, &inf, &sup); |
if ( compnum(0,inf,a) > 0 ) return 0; |
if ( compnum(0,inf,a) > 0 ) return 0; |
else if ( compnum(0,a,sup) > 0 ) return 0; |
else if ( compnum(0,a,sup) > 0 ) return 0; |
else return 1; |
else return 1; |
} |
} |
|
|
int itvinitvp(Itv a, Itv b) |
int itvinitvp(Itv a, Itv b) |
{ |
{ |
Num ai,as,bi,bs; |
Num ai,as,bi,bs; |
|
|
itvtois(a, &ai, &as); |
itvtois(a, &ai, &as); |
itvtois(b, &bi, &bs); |
itvtois(b, &bi, &bs); |
if ( compnum(0,ai,bi) >= 0 && compnum(0,bs,as) >= 0 ) return 1; |
if ( compnum(0,ai,bi) >= 0 && compnum(0,bs,as) >= 0 ) return 1; |
else return 0; |
else return 0; |
} |
} |
|
|
void divitvp(Itv a, Itv b, Itv *c) |
void divitvp(Itv a, Itv b, Itv *c) |
{ |
{ |
Num ai,as,bi,bs,a1,a2,b1,b2,c1,c2,t; |
Num ai,as,bi,bs,a1,a2,b1,b2,c1,c2,t; |
int ba,bb; |
int ba,bb; |
|
|
if ( !b ) |
if ( !b ) |
error("divitv : division by 0"); |
error("divitv : division by 0"); |
else if ( !a ) |
else if ( !a ) |
*c = 0; |
*c = 0; |
else if ( (NID(a) <= N_B) && (NID(b) <= N_B ) ) |
else if ( (NID(a) <= N_B) && (NID(b) <= N_B ) ) |
divnum(0,(Num)a,(Num)b,(Num *)c); |
divnum(0,(Num)a,(Num)b,(Num *)c); |
else if ( (NID(a) == N_IP) && (NID(b) == N_R ) |
else if ( (NID(a) == N_IP) && (NID(b) == N_R ) |
||(NID(a) == N_R ) && (NID(b) == N_IP) ) |
||(NID(a) == N_R ) && (NID(b) == N_IP) ) |
divitvd((Num)a,(Num)b,(IntervalDouble *)c); |
divitvd((Num)a,(Num)b,(IntervalDouble *)c); |
else { |
else { |
itvtois(a,&ai,&as); |
itvtois(a,&ai,&as); |
itvtois(b,&bi,&bs); |
itvtois(b,&bi,&bs); |
chsgnnum(as,&a2); |
chsgnnum(as,&a2); |
chsgnnum(bs,&b2); |
chsgnnum(bs,&b2); |
if ( ba = (compnum(0,0,a2) > 0) ) { |
if ( ba = (compnum(0,0,a2) > 0) ) { |
a1 = ai; |
a1 = ai; |
} else { |
} else { |
a1 = a2; |
a1 = a2; |
a2 = ai; |
a2 = ai; |
} |
} |
if ( bb = (compnum(0,0,b2) > 0) ) { |
if ( bb = (compnum(0,0,b2) > 0) ) { |
b1 = bi; |
b1 = bi; |
} else { |
} else { |
b1 = b2; |
b1 = b2; |
b2 = bi; |
b2 = bi; |
} |
} |
if ( compnum(0,0,b1) >= 0 ) { |
if ( compnum(0,0,b1) >= 0 ) { |
error("divitv : division by interval including 0."); |
error("divitv : division by interval including 0."); |
} else { |
} else { |
divnum(0,a2,b1,&c2); |
divnum(0,a2,b1,&c2); |
if ( compnum(0,0,a1) > 0 ) { |
if ( compnum(0,0,a1) > 0 ) { |
divnum(0,a1,b1,&c1); |
divnum(0,a1,b1,&c1); |
} else { |
} else { |
divnum(0,a1,b2,&t); |
divnum(0,a1,b2,&t); |
subnum(0,0,t,&c1); |
subnum(0,0,t,&c1); |
} |
} |
} |
} |
if ( ba == bb ) { |
if ( ba == bb ) { |
subnum(0,0,c2,&t); |
subnum(0,0,c2,&t); |
istoitv(c1,t,c); |
istoitv(c1,t,c); |
} else { |
} else { |
subnum(0,0,c1,&t); |
subnum(0,0,c1,&t); |
istoitv(c2,t,c); |
istoitv(c2,t,c); |
} |
} |
} |
} |
} |
} |
|
|
void pwritvp(Itv a, Num e, Itv *c) |
void pwritvp(Itv a, Num e, Itv *c) |
{ |
{ |
int ei; |
int ei; |
Itv t; |
Itv t; |
|
|
if ( !e ) |
if ( !e ) |
*c = (Itv)ONE; |
*c = (Itv)ONE; |
else if ( !a ) |
else if ( !a ) |
*c = 0; |
*c = 0; |
else if ( NID(a) <= N_B ) |
else if ( NID(a) <= N_B ) |
pwrnum(0,(Num)a,(Num)e,(Num *)c); |
pwrnum(0,(Num)a,(Num)e,(Num *)c); |
else if ( !INT(e) ) { |
else if ( !INT(e) ) { |
#if defined(PARI) && 0 |
#if defined(PARI) && 0 |
GEN pa,pe,z; |
gpui_ri((Obj)a,(Obj)c,(Obj *)c); |
int ltop,lbot; |
|
|
|
ltop = avma; ritopa(a,&pa); ritopa(e,&pe); lbot = avma; |
|
z = gerepile(ltop,lbot,gpui(pa,pe,prec)); |
|
patori(z,c); cgiv(z); |
|
#else |
#else |
error("pwritv : can't calculate a fractional power"); |
error("pwritv : can't calculate a fractional power"); |
#endif |
#endif |
} else { |
} else { |
ei = QTOS((Q)e); |
ei = QTOS((Q)e); |
pwritv0p(a,ei,&t); |
pwritv0p(a,ei,&t); |
if ( SGN((Q)e) < 0 ) |
if ( SGN((Q)e) < 0 ) |
divnum(0,(Num)ONE,(Num)t,(Num *)c); |
divnum(0,(Num)ONE,(Num)t,(Num *)c); |
else |
else |
*c = t; |
*c = t; |
} |
} |
} |
} |
|
|
void pwritv0p(Itv a, int e, Itv *c) |
void pwritv0p(Itv a, int e, Itv *c) |
{ |
{ |
Num inf, sup; |
Num inf, sup; |
Num ai,Xmin,Xmax; |
Num ai,Xmin,Xmax; |
Q ne; |
Q ne; |
|
|
if ( e == 1 ) |
if ( e == 1 ) |
*c = a; |
*c = a; |
else { |
else { |
STOQ(e,ne); |
STOQ(e,ne); |
if ( !(e%2) ) { |
if ( !(e%2) ) { |
if ( initvp(0,a) ) { |
if ( initvp(0,a) ) { |
Xmin = 0; |
Xmin = 0; |
chsgnnum(INF(a),&ai); |
chsgnnum(INF(a),&ai); |
if ( compnum(0,ai,SUP(a)) > 0 ) { |
if ( compnum(0,ai,SUP(a)) > 0 ) { |
Xmax = ai; |
Xmax = ai; |
} else { |
} else { |
Xmax = SUP(a); |
Xmax = SUP(a); |
} |
} |
} else { |
} else { |
if ( compnum(0,INF(a),0) > 0 ) { |
if ( compnum(0,INF(a),0) > 0 ) { |
Xmin = INF(a); |
Xmin = INF(a); |
Xmax = SUP(a); |
Xmax = SUP(a); |
} else { |
} else { |
Xmin = SUP(a); |
Xmin = SUP(a); |
Xmax = INF(a); |
Xmax = INF(a); |
} |
} |
} |
} |
} else { |
} else { |
Xmin = INF(a); |
Xmin = INF(a); |
Xmax = SUP(a); |
Xmax = SUP(a); |
} |
} |
if ( ! Xmin ) inf = 0; |
if ( ! Xmin ) inf = 0; |
else pwrnum(0,Xmin,(Num)ne,&inf); |
else pwrnum(0,Xmin,(Num)ne,&inf); |
pwrnum(0,Xmax,(Num)ne,&sup); |
pwrnum(0,Xmax,(Num)ne,&sup); |
istoitv(inf,sup,c); |
istoitv(inf,sup,c); |
} |
} |
} |
} |
|
|
void chsgnitvp(Itv a, Itv *c) |
void chsgnitvp(Itv a, Itv *c) |
{ |
{ |
Num inf,sup; |
Num inf,sup; |
|
|
if ( !a ) |
if ( !a ) |
*c = 0; |
*c = 0; |
else if ( NID(a) <= N_B ) |
else if ( NID(a) <= N_B ) |
chsgnnum((Num)a,(Num *)c); |
chsgnnum((Num)a,(Num *)c); |
else { |
else { |
chsgnnum(INF((Itv)a),&inf); |
chsgnnum(INF((Itv)a),&inf); |
chsgnnum(SUP((Itv)a),&sup); |
chsgnnum(SUP((Itv)a),&sup); |
istoitv(inf,sup,c); |
istoitv(inf,sup,c); |
} |
} |
} |
} |
|
|
int cmpitvp(Itv a, Itv b) |
int cmpitvp(Itv a, Itv b) |
{ |
{ |
Num ai,as,bi,bs; |
Num ai,as,bi,bs; |
int s,t; |
int s,t; |
|
|
if ( !a ) { |
if ( !a ) { |
if ( !b || (NID(b)<=N_B) ) |
if ( !b || (NID(b)<=N_B) ) { |
return compnum(0,(Num)a,(Num)b); |
return compnum(0,(Num)a,(Num)b); |
else |
} else { |
return -1; |
itvtois(b,&bi,&bs); |
} else if ( !b ) { |
if ( compnum(0,(Num)a,bs) > 0 ) return 1; |
if ( !a || (NID(a)<=N_B) ) |
else if ( compnum(0,bi,(Num)a) > 0 ) return -1; |
return compnum(0,(Num)a,(Num)b); |
else return 0; |
else |
} |
return initvp((Num)b,a); |
} else if ( !b ) { |
} else { |
if ( !a || (NID(a)<=N_B) ) { |
itvtois(a,&ai,&as); |
return compnum(0,(Num)a,(Num)b); |
itvtois(b,&bi,&bs); |
} else { |
s = compnum(0,ai,bs) ; |
itvtois(a,&ai,&as); |
t = compnum(0,bi,as) ; |
if ( compnum(0,ai,(Num)b) > 0 ) return 1; |
if ( s > 0 ) return 1; |
else if ( compnum(0,(Num)b,as) > 0 ) return -1; |
else if ( t > 0 ) return -1; |
else return 0; |
else return 0; |
} |
} |
} else { |
|
itvtois(a,&ai,&as); |
|
itvtois(b,&bi,&bs); |
|
s = compnum(0,ai,bs) ; |
|
t = compnum(0,bi,as) ; |
|
if ( s > 0 ) return 1; |
|
else if ( t > 0 ) return -1; |
|
else return 0; |
|
} |
} |
} |
|
|
void miditvp(Itv a, Num *b) |
void miditvp(Itv a, Num *b) |
{ |
{ |
Num ai,as; |
Num ai,as; |
Num t; |
Num t; |
Q TWO; |
|
|
|
if ( ! a ) *b = 0; |
if ( ! a ) *b = 0; |
else if ( (NID(a) <= N_B) ) |
else if ( (NID(a) <= N_B) ) |
*b = (Num)a; |
*b = (Num)a; |
else { |
else { |
STOQ(2,TWO); |
STOQ(2,TWO); |
itvtois(a,&ai,&as); |
itvtois(a,&ai,&as); |
addnum(0,ai,as,&t); |
addnum(0,ai,as,&t); |
divnum(0,t,(Num)TWO,b); |
divnum(0,t,(Num)TWO,b); |
} |
} |
} |
} |
|
|
void cupitvp(Itv a, Itv b, Itv *c) |
void cupitvp(Itv a, Itv b, Itv *c) |
{ |
{ |
Num ai,as,bi,bs; |
Num ai,as,bi,bs; |
Num inf,sup; |
Num inf,sup; |
|
|
itvtois(a,&ai,&as); |
itvtois(a,&ai,&as); |
itvtois(b,&bi,&bs); |
itvtois(b,&bi,&bs); |
if ( compnum(0,ai,bi) > 0 ) inf = bi; |
if ( compnum(0,ai,bi) > 0 ) inf = bi; |
else inf = ai; |
else inf = ai; |
if ( compnum(0,as,bs) > 0 ) sup = as; |
if ( compnum(0,as,bs) > 0 ) sup = as; |
else sup = bs; |
else sup = bs; |
istoitv(inf,sup,c); |
istoitv(inf,sup,c); |
} |
} |
|
|
void capitvp(Itv a, Itv b, Itv *c) |
void capitvp(Itv a, Itv b, Itv *c) |
{ |
{ |
Num ai,as,bi,bs; |
Num ai,as,bi,bs; |
Num inf,sup; |
Num inf,sup; |
|
|
itvtois(a,&ai,&as); |
itvtois(a,&ai,&as); |
itvtois(b,&bi,&bs); |
itvtois(b,&bi,&bs); |
if ( compnum(0,ai,bi) > 0 ) inf = ai; |
if ( compnum(0,ai,bi) > 0 ) inf = ai; |
else inf = bi; |
else inf = bi; |
if ( compnum(0,as,bs) > 0 ) sup = bs; |
if ( compnum(0,as,bs) > 0 ) sup = bs; |
else sup = as; |
else sup = as; |
if ( compnum(0,inf,sup) > 0 ) *c = 0; |
if ( compnum(0,inf,sup) > 0 ) *c = 0; |
else istoitv(inf,sup,c); |
else istoitv(inf,sup,c); |
} |
} |
|
|
|
|
void widthitvp(Itv a, Num *b) |
void widthitvp(Itv a, Num *b) |
{ |
{ |
Num ai,as; |
Num ai,as; |
|
|
if ( ! a ) *b = 0; |
if ( ! a ) *b = 0; |
else if ( (NID(a) <= N_B) ) |
else if ( (NID(a) <= N_B) ) |
*b = (Num)a; |
*b = (Num)a; |
else { |
else { |
itvtois(a,&ai,&as); |
itvtois(a,&ai,&as); |
subnum(0,as,ai,b); |
subnum(0,as,ai,b); |
} |
} |
} |
} |
|
|
void absitvp(Itv a, Num *b) |
void absitvp(Itv a, Num *b) |
{ |
{ |
Num ai,as,bi,bs; |
Num ai,as,bi,bs; |
|
|
if ( ! a ) *b = 0; |
if ( ! a ) *b = 0; |
else if ( (NID(a) <= N_B) ) { |
else if ( (NID(a) <= N_B) ) { |
if ( compnum(0,(Num)a,0) < 0 ) chsgnnum((Num)a,b); |
if ( compnum(0,(Num)a,0) < 0 ) chsgnnum((Num)a,b); |
else *b = (Num)a; |
else *b = (Num)a; |
} else { |
} else { |
itvtois(a,&ai,&as); |
itvtois(a,&ai,&as); |
if ( compnum(0,ai,0) < 0 ) chsgnnum(ai,&bi); |
if ( compnum(0,ai,0) < 0 ) chsgnnum(ai,&bi); |
else bi = ai; |
else bi = ai; |
if ( compnum(0,as,0) < 0 ) chsgnnum(as,&bs); |
if ( compnum(0,as,0) < 0 ) chsgnnum(as,&bs); |
else bs = as; |
else bs = as; |
if ( compnum(0,bi,bs) > 0 ) *b = bi; |
if ( compnum(0,bi,bs) > 0 ) *b = bi; |
else *b = bs; |
else *b = bs; |
} |
} |
} |
} |
|
|
void distanceitvp(Itv a, Itv b, Num *c) |
void distanceitvp(Itv a, Itv b, Num *c) |
{ |
{ |
Num ai,as,bi,bs; |
Num ai,as,bi,bs; |
Num di,ds; |
Num di,ds; |
Itv d; |
Itv d; |
|
|
itvtois(a,&ai,&as); |
itvtois(a,&ai,&as); |
itvtois(b,&bi,&bs); |
itvtois(b,&bi,&bs); |
subnum(0,ai,bi,&di); |
subnum(0,ai,bi,&di); |
subnum(0,as,bs,&ds); |
subnum(0,as,bs,&ds); |
istoitv(di,ds,&d); |
istoitv(di,ds,&d); |
absitvp(d,c); |
absitvp(d,c); |
} |
} |
|
|
#endif |
#endif |