[BACK]Return to interval.h CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2018 / include

Annotation of OpenXM_contrib2/asir2018/include/interval.h, Revision 1.4

1.1       noro        1: /*
1.4     ! kondoh      2:  * $OpenXM: OpenXM_contrib2/asir2018/include/interval.h,v 1.3 2019/10/17 03:03:12 kondoh Exp $
1.1       noro        3: */
                      4: #ifndef  _INTERVAL_H
                      5: #define  _INTERVAL_H
                      6:
                      7: #define  PRINTF_G  0
                      8: #define  PRINTF_E  1
                      9:
1.4     ! kondoh     10: #define        INT_ASIR_VERSION        20191111
1.2       kondoh     11:
1.1       noro       12: #if defined(INTERVAL)
1.4     ! kondoh     13: #if INTERVAL == 0
        !            14: #undef INTERVAL
        !            15: #endif
        !            16: #endif
        !            17: #if defined(INTERVAL)
1.1       noro       18:
                     19: #include <math.h>
                     20:
                     21: #ifdef  sun
                     22: #if OSMajorVersion < 4 || (OSMajorVersion == 4 && OSMinorVersion < 1)
                     23: #include <sys/ieeefp.h>
                     24: #endif
                     25: #if defined(__svr4__)
                     26: #include  <ieeefp.h>
                     27: #define  FPNEAREST  fpsetround(FP_RN);
                     28: #define  FPPLUSINF  fpsetround(FP_RP);
                     29: #define  FPMINUSINF  fpsetround(FP_RM);
                     30: #define  FPTOZERO  fpsetround(FP_RZ);
                     31: #else
                     32: static char  *Interval_dummy;
                     33: #define  FPNEAREST  ieee_flags("clear", "direction", Interval_dummy, &Interval_dummy);
                     34: #define  FPPLUSINF  ieee_flags("set", "direction", "positive", &Interval_dummy);
                     35: #define  FPMINUSINF  ieee_flags("set", "direction", "negative", &Interval_dummy);
                     36: #define  FPTOZERO  ieee_flags("set", "direction", "tozero", &Interval_dummy);
                     37: #endif
                     38: #endif
                     39:
1.2       kondoh     40: #if 0
1.1       noro       41: #ifdef  linux
                     42: #include  <fpu_control.h>
                     43: #if 1
                     44:
                     45: #if defined(__ARM_ARCH) || defined(ANDROID)
                     46: #ifndef _FPU_RC_NEAREST
                     47: #define _FPU_RC_NEAREST 0x0
                     48: #endif
                     49: #ifndef _FPU_RC_DOWN
                     50: #define _FPU_RC_DOWN    0x400
                     51: #endif
                     52: #ifndef _FPU_RC_UP
                     53: #define _FPU_RC_UP      0x800
                     54: #endif
                     55: #ifndef _FPU_RC_ZERO
                     56: #define _FPU_RC_ZERO    0xC00
                     57: #endif
                     58: #endif /* __ARM_ARCH */
                     59:
                     60: #define  LINUX_FPU_RC_MASK        0xf3ff
                     61: #define  LINUX_FPU_SETCW(c)      \
                     62: {fpu_control_t __tmp__; _FPU_GETCW(__fpu_control);\
                     63:  __tmp__ = (__fpu_control & LINUX_FPU_RC_MASK | c);\
                     64:  _FPU_SETCW(__tmp__);}
                     65: #define  FPNEAREST  LINUX_FPU_SETCW(_FPU_RC_NEAREST);
                     66: #define  FPPLUSINF  LINUX_FPU_SETCW(_FPU_RC_UP);
                     67: #define  FPMINUSINF  LINUX_FPU_SETCW(_FPU_RC_DOWN);
                     68: #define  FPTOZERO    LINUX_FPU_SETCW(_FPU_RC_ZERO);
                     69: #else
                     70: #define  _FPU_DEFAULT_p_FPU_RC_UP  0x1b72
                     71: #define  _FPU_DEFAULT_p_FPU_RC_DOWN  0x1772
                     72: #define  _FPU_DEFAULT_p_FPU_RC_ZERO  0x1f72
                     73: #define  FPNEAREST  __setfpucw(_FPU_DEFAULT);
                     74: #define  FPPLUSINF  __setfpucw(_FPU_DEFAULT_p_FPU_RC_UP);
                     75: #define  FPMINUSINF  __setfpucw(_FPU_DEFAULT_p_FPU_RC_DOWN);
                     76: #define  FPTOZERO  __setfpucw(_FPU_DEFAULT_p_FPU_RC_ZERO);
                     77: #endif
                     78: #endif
                     79:
                     80: #if defined(__osf__)
                     81: #if 0
                     82: #include  <float.h>
                     83: #define  FPNEAREST  write_rnd(FP_RND_RN);
                     84: #define  FPPLUSINF  write_rnd(FP_RND_RP);
                     85: #define  FPMINUSINF  write_rnd(FP_RND_RM);
                     86: #define  FPTOZERO  write_rnd(FP_RND_RZ);
                     87: #else
                     88: #define  FPNEAREST
                     89: #define  FPPLUSINF
                     90: #define  FPMINUSINF
                     91: #define  FPTOZERO
                     92: #endif
                     93: #endif
                     94:
                     95: #if defined(__FreeBSD__) && defined(__GNUC__)
                     96: #include  <floatingpoint.h>
                     97: #define  FPNEAREST  fpsetround(FP_RN);
                     98: #define  FPPLUSINF  fpsetround(FP_RP);
                     99: #define  FPMINUSINF  fpsetround(FP_RM);
                    100: #define  FPTOZERO  fpsetround(FP_RZ);
                    101: #endif
                    102:
                    103: #if defined(VISUAL) || defined(__MINGW32__)
                    104: #include <float.h>
                    105: #define FPNEAREST _controlfp(_RC_NEAR,_MCW_RC);
                    106: #define FPPLUSINF _controlfp(_RC_UP,_MCW_RC);
                    107: #define FPMINUSINF _controlfp(_RC_DOWN,_MCW_RC);
                    108: #define FPTOZERO _controlfp(_RC_CHOP,_MCW_RC);
                    109: #endif
1.2       kondoh    110: #endif
                    111: #include <fenv.h>
                    112:
                    113: #define        FPNEAREST       fesetround(FE_TONEAREST);
                    114: #define        FPPLUSINF       fesetround(FE_UPWARD);
                    115: #define        FPMINUSINF      fesetround(FE_DOWNWARD);
                    116: #define        FPTOZERO        fesetround(FE_TOWARDZERO);
                    117:
1.1       noro      118:
                    119: /* no control function of floating point rounding */
                    120: #ifndef FPNEAREST
                    121: #define  FPNEAREST  fprintf(stderr, "Fpu control FPNEAREST is not supported in this machine yet.\n");
                    122: #endif
                    123: #ifndef FPMINUSINF
                    124: #define  FPMINUSINF  fprintf(stderr, "Fpu control FPMINUSINF is not supported in this machine yet.\n");
                    125: #endif
                    126: #ifndef FPPLUSINF
                    127: #define  FPPLUSINF  fprintf(stderr, "Fpu control FPPLUSINF is not supported in this machine yet.\n");
                    128: #endif
                    129: #ifndef FPTOZERO
                    130: #define  FPTOZERO  fprintf(stderr, "Fpu control FPZERO is not supported in this machine yet.\n");
                    131: #endif
                    132: #define FPCLEAR    FPNEAREST
                    133:
                    134: #define  MID_PRINTF_G  2
                    135: #define  MID_PRINTF_E  3
                    136:
1.2       kondoh    137: #define DEFAULTPREC    0       /* for mpfr */
                    138:
1.1       noro      139: /* data structures */
                    140: struct oItv {
                    141:         short  id;
                    142:         char  nid;
                    143:         char  pad;
                    144:         Num  inf;
                    145:         Num  sup;
                    146: };
                    147:
                    148: typedef struct oItv *Itv;
                    149:
                    150: struct oIntervalDouble {
                    151:         short  id;
                    152:         char  nid;
                    153:         char  pad;
                    154:         double  inf;
                    155:         double  sup;
                    156: };
                    157:
                    158: typedef struct oIntervalDouble *IntervalDouble;
                    159:
                    160: struct oforth {
                    161:   short  sign;
                    162:   short  exp;
                    163:   double  u;
                    164:   double  l;
                    165: };
                    166:
                    167: typedef struct oforth *forth;
                    168:
                    169: struct oIntervalQuad {
                    170:         short  id;
                    171:         char  nid;
                    172:         char  pad;
                    173:         forth  inf;
                    174:         forth  sup;
                    175: };
                    176:
                    177: typedef struct oIntervalQuad *IntervalQuad;
                    178:
                    179: struct oIntervalBigFloat {
                    180:         short  id;
                    181:         char  nid;
                    182:         char  pad;
                    183:         BF  inf;
                    184:         BF  sup;
                    185: };
                    186:
                    187: typedef struct oIntervalBigFloat *IntervalBigFloat;
                    188:
                    189: extern int zerorewrite;
1.2       kondoh    190: extern int zerorewriteCount;
1.1       noro      191:
1.4     ! kondoh    192: #define        ZEROREWRITE       if (zerorewrite && initvp(0,c) ) { *rp = 0; zerorewriteCount++; }
        !           193:
1.1       noro      194: /* general macros */
                    195: #define INF(p)  ((p)->inf)
                    196: #define SUP(p)  ((p)->sup)
                    197:
                    198: #define NEWItvP(q)  ((q)=(Itv)MALLOC(sizeof(struct oItv)),\
                    199:           OID(q)=O_N,NID(q)=N_IP)
                    200: #define NEWIntervalDouble(q)  ((q)=(IntervalDouble)MALLOC(sizeof(struct oIntervalDouble)),\
                    201:           OID(q)=O_N,NID(q)=N_IntervalDouble)
                    202: #define NEWIntervalQuad(q)  ((q)=(IntervalDouble)MALLOC(sizeof(struct oIntervalQuad)),\
                    203:           OID(q)=O_N,NID(q)=N_IntervalQuad)
                    204: #define NEWIntervalBigFloat(q)  ((q)=(IntervalBigFloat)MALLOC(sizeof(struct oIntervalBigFloat)),\
                    205:           OID(q)=O_N,NID(q)=N_IntervalBigFloat)
                    206: #define MKItvP(a,b,c)  (NEWItvP(c),(INF(c)=(a),SUP(c)=(b)))
1.2       kondoh    207: #define MKIntervalDouble(a,b,c)  if((zerorewrite) && ((a)<=0.0) && ((b)>=0.0)) {(c)=0;zerorewriteCount++;}\
                    208:        else (NEWIntervalDouble(c),(INF(c)=(a),SUP(c)=(b)))
1.1       noro      209: #define MKIntervalQuad(a,b,c)  (NEWIntervalQuad(c),(INF(c)=(a),SUP(c)=(b)))
                    210: #define MKIntervalBigFloat(a,b,c)  (NEWIntervalBigFloat(c),(INF(c)=(a),SUP(c)=(b)))
                    211:
                    212: #define ToItvP(a,c)  (NEWItvP(c),INF(c)=(a),SUP(c)=(a))
1.4     ! kondoh    213: #define ToIntervalDouble(a,c)  (NEWIntervalDouble(c),INF(c)=(toRealDown(a)),SUP(c)=(toRealUp(a)))
1.1       noro      214: #define ToIntervalBigFloat(a,c)  (NEWIntervalBigFloat(c),INF(c)=(a),SUP(c)=(a))
                    215:
                    216: #define ITVP(a) (NID(a)==N_IP)
                    217: #define ITVD(a) (NID(a)==N_IntervalDouble)
                    218: #define ITVQ(a) (NID(a)==N_IntervalQuad)
                    219: #define ITVF(a) (NID(a)==N_IntervalBigFloat)
                    220:
1.4     ! kondoh    221: #define        EvalIntervalDouble              0
        !           222: #define        EvalIntervalQuad                1
        !           223: #define        EvalIntervalBigFloat    2
        !           224:
1.2       kondoh    225: #if 0
1.1       noro      226: double  ToRealSup(Num);
                    227: double  ToRealInf(Num);
                    228: double  RatnToRealUp(Q);
1.2       kondoh    229: double  NatToRealUp(N, int *);
1.1       noro      230:
                    231: void  double2bf(double, BF *);
                    232: double  bf2double(BF);
                    233:
                    234:
                    235: void    additv(Num, Num, Num *);
                    236: void    subitv(Num, Num, Num *);
                    237: void    mulitv(Num, Num, Num *);
                    238: int     initv(Num, double);
                    239: int     itvinitv(Itv, Itv);
                    240: void    divitv(Num, Num, Num *);
                    241: void    sqrtitv(Num, Num *);
                    242: void    pwritv(Num, Num, Num *);
1.3       kondoh    243: void    pwritv0(Itv, long, Itv *);
1.1       noro      244: void    chsgnitv(Num, Num *);
                    245: void    miditv(Itv, Num *);
                    246: int     cmpitv(Itv, Itv);
                    247: void    cupitv(Itv, Itv, Itv *);
                    248: void    capitv(Itv, Itv, Itv *);
                    249: void    widthitv(Itv, Num *);
                    250: void    distanceitv(Itv, Itv, Num *);
                    251: #endif
                    252:
1.2       kondoh    253: /***    engine/p-itv.c    ***/
                    254: void  itvtois(Itv, Num *, Num *);
                    255: void  istoitv(Num, Num, Itv *);
                    256:
1.1       noro      257: void    additvp(Itv, Itv, Itv *);
                    258: void    subitvp(Itv, Itv, Itv *);
                    259: void    mulitvp(Itv, Itv, Itv *);
                    260: void    divitvp(Itv, Itv, Itv *);
1.2       kondoh    261: void    pwritvp(Itv, Num, Itv *);
1.3       kondoh    262: void    pwritv0p(Itv, long, Itv *);
1.1       noro      263: void    chsgnitvp(Itv, Itv *);
1.2       kondoh    264: int     initvp(Num , Itv );
                    265: int     itvinitvp(Itv, Itv);
1.1       noro      266: int     cmpitvp(Itv, Itv);
1.2       kondoh    267: void miditvp(Itv, Num *);
1.1       noro      268: void    cupitvp(Itv, Itv, Itv *);
                    269: void    capitvp(Itv, Itv, Itv *);
                    270: void    widthitvp(Itv, Num *);
1.4     ! kondoh    271: void   absitvp(Itv, Num *);
        !           272: void   absintvalp(Itv, Itv *);
1.1       noro      273: void    distanceitvp(Itv, Itv, Num *);
                    274:
1.2       kondoh    275:
                    276: /***    engine/f-itv.c    ***/
                    277:
                    278: //void  ToBf(Num, BF *);
                    279: //void  double2bf(double, BF *);
                    280: //double  bf2double(BF);
                    281: //void  addulp(IntervalBigFloat, IntervalBigFloat *);
                    282: //void  getulp(BF, BF *);
1.4     ! kondoh    283: double mpfr2dblDown(mpfr_t);
        !           284: double mpfr2dblUp(mpfr_t);
        !           285: void toInterval(Num, int, int, Num *);
1.1       noro      286:
                    287: void    additvf(IntervalBigFloat, IntervalBigFloat, IntervalBigFloat *);
                    288: void    subitvf(IntervalBigFloat, IntervalBigFloat, IntervalBigFloat *);
                    289: void    mulitvf(IntervalBigFloat, IntervalBigFloat, IntervalBigFloat *);
                    290: void    divitvf(IntervalBigFloat, IntervalBigFloat, IntervalBigFloat *);
1.2       kondoh    291: void    chsgnitvf(IntervalBigFloat, IntervalBigFloat *);
                    292: int     initvf(Num, Itv);
                    293: int     itvinitvf(Itv, Itv);
1.1       noro      294: int     cmpitvf(Itv, Itv);
                    295: void    pwritvf(Itv, Num, Itv *);
1.3       kondoh    296: void    pwritv0f(Itv, long, Itv *);
1.2       kondoh    297: void miditvf(Itv, Num *);
                    298: void cupitvf(Itv, Itv, Itv *);
                    299: void capitvf(Itv, Itv, Itv *);
                    300: void widthitvf(Itv, Num *);
                    301: void absitvf(Itv, Num *);
                    302: void distanceitvf(Itv, Itv, Num *);
1.1       noro      303:
                    304: /***    engine/d-itv.c    ***/
1.4     ! kondoh    305: double  toRealDown(Num);
        !           306: double  toRealUp(Num);
1.1       noro      307: void  Num2double(Num, double *, double *);
                    308:
                    309: void    additvd(Num, Num, IntervalDouble *);
                    310: void    subitvd(Num, Num, IntervalDouble *);
                    311: void    mulitvd(Num, Num, IntervalDouble *);
                    312: void    divitvd(Num, Num, IntervalDouble *);
                    313: void    chsgnitvd(IntervalDouble, IntervalDouble *);
1.2       kondoh    314: int     initvd(Num, IntervalDouble);
1.1       noro      315: int     cmpitvd(IntervalDouble, IntervalDouble);
                    316: void    pwritvd(Num, Num, IntervalDouble *);
1.3       kondoh    317: void    pwritv0d(IntervalDouble, long, IntervalDouble *);
1.1       noro      318: void    miditvd(IntervalDouble, Num *);
                    319: void    cupitvd(IntervalDouble, IntervalDouble, IntervalDouble *);
                    320: void    capitvd(IntervalDouble, IntervalDouble, IntervalDouble *);
                    321: void    widthitvd(IntervalDouble, Num *);
                    322: void    absitvd(IntervalDouble, Num *);
1.4     ! kondoh    323: void    absintvald(IntervalDouble, IntervalDouble *);
1.1       noro      324: void    distanceitvd(IntervalDouble, IntervalDouble, Num *);
                    325:
1.4     ! kondoh    326: /***    builtin/itvnum.c    ***/
        !           327:
        !           328: void evalitvr(VL ,Obj ,int , int , Obj *);
        !           329: void evalitvp(VL ,P ,int , int , P *);
        !           330: void evalitvv(VL ,V ,int , int , Obj *);
        !           331: //void evalitvins(PFINS ,int , int , Obj *);
        !           332: extern void (*pi_itv_ft[])();
        !           333: extern void (*e_itv_ft[])();
        !           334: extern void (*sin_itv_ft[])();
        !           335: extern void (*cos_itv_ft[])();
        !           336: extern void (*tan_itv_ft[])();
        !           337: extern void (*asin_itv_ft[])();
        !           338: extern void (*acos_itv_ft[])();
        !           339: extern void (*atan_itv_ft[])();
        !           340: extern void (*sinh_itv_ft[])();
        !           341: extern void (*cosh_itv_ft[])();
        !           342: extern void (*tanh_itv_ft[])();
        !           343: extern void (*asinh_itv_ft[])();
        !           344: extern void (*acosh_itv_ft[])();
        !           345: extern void (*atanh_itv_ft[])();
        !           346: extern void (*exp_itv_ft[])();
        !           347: extern void (*log_itv_ft[])();
        !           348: extern void (*abs_itv_ft[])();
        !           349: extern void (*pow_itv_ft[])();
        !           350: //void devalr(VL ,Obj ,Obj *);
        !           351: //void devalp(VL ,P ,P *);
        !           352: //void devalv(VL ,V ,Obj *);
        !           353: //void devalins(PFINS ,Obj *);
        !           354:
        !           355: void Pitvbf_pi(NODE ,Obj *);
        !           356: void Pitvbf_e(NODE ,Obj *);
        !           357: void Pitvbf_sin(NODE ,Obj *);
        !           358: void Pitvbf_cos(NODE ,Obj *);
        !           359: void Pitvbf_tan(NODE ,Obj *);
        !           360: void Pitvbf_asin(NODE ,Obj *);
        !           361: void Pitvbf_acos(NODE ,Obj *);
        !           362: void Pitvbf_atan(NODE ,Obj *);
        !           363: void Pitvbf_sinh(NODE ,Obj *);
        !           364: void Pitvbf_cosh(NODE ,Obj *);
        !           365: void Pitvbf_tanh(NODE ,Obj *);
        !           366: void Pitvbf_asinh(NODE ,Obj *);
        !           367: void Pitvbf_acosh(NODE ,Obj *);
        !           368: void Pitvbf_atanh(NODE ,Obj *);
        !           369: void Pitvbf_exp(NODE ,Obj *);
        !           370: void Pitvbf_log(NODE ,Obj *);
        !           371: void Pitvbf_abs(NODE ,Obj *);
        !           372: //void mp_factorial(NODE ,Num *);
        !           373: void Pitvbf_pow(NODE ,Num *);
        !           374:
        !           375: void Pitvd_pi(NODE ,Obj *);
        !           376: void Pitvd_e(NODE ,Obj *);
        !           377: void Pitvd_sin(NODE ,Obj *);
        !           378: void Pitvd_cos(NODE ,Obj *);
        !           379: void Pitvd_tan(NODE ,Obj *);
        !           380: void Pitvd_asin(NODE ,Obj *);
        !           381: void Pitvd_acos(NODE ,Obj *);
        !           382: void Pitvd_atan(NODE ,Obj *);
        !           383: void Pitvd_sinh(NODE ,Obj *);
        !           384: void Pitvd_cosh(NODE ,Obj *);
        !           385: void Pitvd_tanh(NODE ,Obj *);
        !           386: void Pitvd_asinh(NODE ,Obj *);
        !           387: void Pitvd_acosh(NODE ,Obj *);
        !           388: void Pitvd_atanh(NODE ,Obj *);
        !           389: void Pitvd_exp(NODE ,Obj *);
        !           390: void Pitvd_log(NODE ,Obj *);
        !           391: void Pitvd_abs(NODE ,Obj *);
        !           392: void Pitvd_pow(NODE ,Num *);
        !           393:
1.1       noro      394: #endif /* end of INTERVAL */
                    395: #endif /* end of _INTERVAL_H */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>