version 1.8, 2018/03/29 01:32:52 |
version 1.11, 2019/11/12 10:52:04 |
|
|
/* |
/* |
* $OpenXM: OpenXM_contrib2/asir2000/engine/p-itv.c,v 1.7 2009/03/27 14:42:29 ohara Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/engine/p-itv.c,v 1.10 2019/11/07 08:47:35 kondoh Exp $ |
*/ |
*/ |
#if defined(INTERVAL) |
#if defined(INTERVAL) |
#include "ca.h" |
#include "ca.h" |
#include "base.h" |
#include "base.h" |
|
#if 0 |
#if defined(PARI) |
#if defined(PARI) |
#include "genpari.h" |
#include "genpari.h" |
#endif |
#endif |
|
#endif |
|
|
|
// in engine/bf.c |
|
Num tobf(Num,int); |
|
//int initvp(Num , Itv ); |
|
|
|
extern int mpfr_roundmode; |
extern int zerorewrite; |
extern int zerorewrite; |
|
|
void itvtois(Itv a, Num *inf, Num *sup) |
void itvtois(Itv a, Num *inf, Num *sup) |
Line 16 void itvtois(Itv a, Num *inf, Num *sup) |
|
Line 23 void itvtois(Itv a, Num *inf, Num *sup) |
|
*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 if ( ITVD(a) ) { |
|
double dinf, dsup; |
|
Real rinf, rsup; |
|
dinf = INF((IntervalDouble)a); dsup = SUP((IntervalDouble)a); |
|
MKReal(dinf, rinf); MKReal(dsup, rsup); |
|
*inf = (Num)rinf; *sup = (Num)rsup; |
} else { |
} else { |
*inf = INF(a); |
*inf = INF(a); |
*sup = SUP(a); |
*sup = SUP(a); |
Line 24 void itvtois(Itv a, Num *inf, Num *sup) |
|
Line 37 void itvtois(Itv a, Num *inf, Num *sup) |
|
|
|
void istoitv(Num inf, Num sup, Itv *rp) |
void istoitv(Num inf, Num sup, Itv *rp) |
{ |
{ |
Num i, s; |
Num ii, ss; |
|
Num ni, ns; |
Itv c; |
Itv c; |
int type=0; |
int type=0; |
|
int current_roundmode; |
|
|
if ( !inf && !sup ) { |
if ( !inf && !sup ) { |
*rp = 0; |
*rp = 0; |
return; |
return; |
} |
} |
if ( !sup ) { |
if ( compnum(0,sup,inf) >= 0 ) { |
s = 0; |
ns = sup; ni = inf; |
|
} else { |
|
ni = sup; ns = inf; |
} |
} |
else if ( NID( sup )==N_B ) { |
|
|
current_roundmode = mpfr_roundmode; |
|
if ( !ns ) { |
|
ss = 0; |
|
} |
|
else if ( NID( ns )==N_B ) { |
type = 1; |
type = 1; |
ToBf(sup, (BF *)&s); |
|
|
mpfr_roundmode = MPFR_RNDU; |
|
ss = tobf(ns, DEFAULTPREC); |
|
//ToBf(sup, (BF *)&s); |
} else { |
} else { |
s = sup; |
ss = ns; |
} |
} |
if ( !inf ) { |
if ( !ni ) { |
i = 0; |
ii = 0; |
} |
} |
else if ( NID( inf )==N_B ) { |
else if ( NID( ni )==N_B ) { |
type = 1; |
type = 1; |
ToBf(inf, (BF *)&i); |
|
|
mpfr_roundmode = MPFR_RNDD; |
|
ii = tobf(ni, DEFAULTPREC); |
|
//ToBf(inf, (BF *)&i); |
} else { |
} else { |
i = inf; |
ii = ni; |
} |
} |
if ( type ) { |
mpfr_roundmode = current_roundmode; |
// NEWIntervalBigFloat((IntervalBigFloat)c); |
|
c=MALLOC(sizeof(struct oIntervalBigFloat)); |
|
OID(c)=O_N; |
|
NID(c)=N_IntervalBigFloat; |
|
} else |
|
NEWItvP(c); |
|
|
|
if ( compnum(0,i,s) >= 0 ) { |
if ( type ) { |
INF(c) = s; SUP(c) = i; |
IntervalBigFloat cc; |
|
NEWIntervalBigFloat(cc); |
|
c = (Itv)cc; |
} else { |
} else { |
INF(c) = i; SUP(c) = s; |
NEWItvP(c); |
} |
} |
|
INF(c) = ii; SUP(c) = ss; |
|
|
if (zerorewrite) |
|
if ( initvp(0,c) ) { |
|
*rp = 0; |
|
return; |
|
} |
|
*rp = c; |
*rp = c; |
|
|
|
ZEROREWRITE |
} |
} |
|
|
void additvp(Itv a, Itv b, Itv *c) |
void additvp(Itv a, Itv b, Itv *c) |
Line 442 void absitvp(Itv a, Num *b) |
|
Line 464 void absitvp(Itv a, Num *b) |
|
else *b = bs; |
else *b = bs; |
} |
} |
} |
} |
|
|
|
void absintvalp(Itv a, Itv *c) |
|
{ |
|
Num ai,as,mai; |
|
Num inf,sup; |
|
|
|
itvtois(a,&ai,&as); |
|
if ( compnum(0,as,0 ) < 0 ) { |
|
chsgnnum(ai, &sup); |
|
chsgnnum(as, &inf); |
|
} else if ( compnum(0,ai,0) < 0 ) { |
|
inf = 0; |
|
chsgnnum(ai, &mai); |
|
if ( compnum(0,as,mai ) > 0 ) sup = as; |
|
else sup = mai; |
|
} else { |
|
inf = ai; |
|
sup = as; |
|
} |
|
istoitv(inf,sup,c); |
|
} |
|
|
|
|
void distanceitvp(Itv a, Itv b, Num *c) |
void distanceitvp(Itv a, Itv b, Num *c) |
{ |
{ |