[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.2

1.1       noro        1: /*
1.2     ! kondoh      2:  * $OpenXM: OpenXM_contrib2/asir2018/include/interval.h,v 1.1 2018/09/19 06:00:58 noro 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.2     ! kondoh     10: #define        INT_ASIR_VERSION        20181218
        !            11:
1.1       noro       12: #if defined(INTERVAL)
                     13:
                     14: #include <math.h>
                     15:
                     16: #ifdef  sun
                     17: #if OSMajorVersion < 4 || (OSMajorVersion == 4 && OSMinorVersion < 1)
                     18: #include <sys/ieeefp.h>
                     19: #endif
                     20: #if defined(__svr4__)
                     21: #include  <ieeefp.h>
                     22: #define  FPNEAREST  fpsetround(FP_RN);
                     23: #define  FPPLUSINF  fpsetround(FP_RP);
                     24: #define  FPMINUSINF  fpsetround(FP_RM);
                     25: #define  FPTOZERO  fpsetround(FP_RZ);
                     26: #else
                     27: static char  *Interval_dummy;
                     28: #define  FPNEAREST  ieee_flags("clear", "direction", Interval_dummy, &Interval_dummy);
                     29: #define  FPPLUSINF  ieee_flags("set", "direction", "positive", &Interval_dummy);
                     30: #define  FPMINUSINF  ieee_flags("set", "direction", "negative", &Interval_dummy);
                     31: #define  FPTOZERO  ieee_flags("set", "direction", "tozero", &Interval_dummy);
                     32: #endif
                     33: #endif
                     34:
1.2     ! kondoh     35: #if 0
1.1       noro       36: #ifdef  linux
                     37: #include  <fpu_control.h>
                     38: #if 1
                     39:
                     40: #if defined(__ARM_ARCH) || defined(ANDROID)
                     41: #ifndef _FPU_RC_NEAREST
                     42: #define _FPU_RC_NEAREST 0x0
                     43: #endif
                     44: #ifndef _FPU_RC_DOWN
                     45: #define _FPU_RC_DOWN    0x400
                     46: #endif
                     47: #ifndef _FPU_RC_UP
                     48: #define _FPU_RC_UP      0x800
                     49: #endif
                     50: #ifndef _FPU_RC_ZERO
                     51: #define _FPU_RC_ZERO    0xC00
                     52: #endif
                     53: #endif /* __ARM_ARCH */
                     54:
                     55: #define  LINUX_FPU_RC_MASK        0xf3ff
                     56: #define  LINUX_FPU_SETCW(c)      \
                     57: {fpu_control_t __tmp__; _FPU_GETCW(__fpu_control);\
                     58:  __tmp__ = (__fpu_control & LINUX_FPU_RC_MASK | c);\
                     59:  _FPU_SETCW(__tmp__);}
                     60: #define  FPNEAREST  LINUX_FPU_SETCW(_FPU_RC_NEAREST);
                     61: #define  FPPLUSINF  LINUX_FPU_SETCW(_FPU_RC_UP);
                     62: #define  FPMINUSINF  LINUX_FPU_SETCW(_FPU_RC_DOWN);
                     63: #define  FPTOZERO    LINUX_FPU_SETCW(_FPU_RC_ZERO);
                     64: #else
                     65: #define  _FPU_DEFAULT_p_FPU_RC_UP  0x1b72
                     66: #define  _FPU_DEFAULT_p_FPU_RC_DOWN  0x1772
                     67: #define  _FPU_DEFAULT_p_FPU_RC_ZERO  0x1f72
                     68: #define  FPNEAREST  __setfpucw(_FPU_DEFAULT);
                     69: #define  FPPLUSINF  __setfpucw(_FPU_DEFAULT_p_FPU_RC_UP);
                     70: #define  FPMINUSINF  __setfpucw(_FPU_DEFAULT_p_FPU_RC_DOWN);
                     71: #define  FPTOZERO  __setfpucw(_FPU_DEFAULT_p_FPU_RC_ZERO);
                     72: #endif
                     73: #endif
                     74:
                     75: #if defined(__osf__)
                     76: #if 0
                     77: #include  <float.h>
                     78: #define  FPNEAREST  write_rnd(FP_RND_RN);
                     79: #define  FPPLUSINF  write_rnd(FP_RND_RP);
                     80: #define  FPMINUSINF  write_rnd(FP_RND_RM);
                     81: #define  FPTOZERO  write_rnd(FP_RND_RZ);
                     82: #else
                     83: #define  FPNEAREST
                     84: #define  FPPLUSINF
                     85: #define  FPMINUSINF
                     86: #define  FPTOZERO
                     87: #endif
                     88: #endif
                     89:
                     90: #if defined(__FreeBSD__) && defined(__GNUC__)
                     91: #include  <floatingpoint.h>
                     92: #define  FPNEAREST  fpsetround(FP_RN);
                     93: #define  FPPLUSINF  fpsetround(FP_RP);
                     94: #define  FPMINUSINF  fpsetround(FP_RM);
                     95: #define  FPTOZERO  fpsetround(FP_RZ);
                     96: #endif
                     97:
                     98: #if defined(VISUAL) || defined(__MINGW32__)
                     99: #include <float.h>
                    100: #define FPNEAREST _controlfp(_RC_NEAR,_MCW_RC);
                    101: #define FPPLUSINF _controlfp(_RC_UP,_MCW_RC);
                    102: #define FPMINUSINF _controlfp(_RC_DOWN,_MCW_RC);
                    103: #define FPTOZERO _controlfp(_RC_CHOP,_MCW_RC);
                    104: #endif
1.2     ! kondoh    105: #endif
        !           106: #include <fenv.h>
        !           107:
        !           108: #define        FPNEAREST       fesetround(FE_TONEAREST);
        !           109: #define        FPPLUSINF       fesetround(FE_UPWARD);
        !           110: #define        FPMINUSINF      fesetround(FE_DOWNWARD);
        !           111: #define        FPTOZERO        fesetround(FE_TOWARDZERO);
        !           112:
1.1       noro      113:
                    114: /* no control function of floating point rounding */
                    115: #ifndef FPNEAREST
                    116: #define  FPNEAREST  fprintf(stderr, "Fpu control FPNEAREST is not supported in this machine yet.\n");
                    117: #endif
                    118: #ifndef FPMINUSINF
                    119: #define  FPMINUSINF  fprintf(stderr, "Fpu control FPMINUSINF is not supported in this machine yet.\n");
                    120: #endif
                    121: #ifndef FPPLUSINF
                    122: #define  FPPLUSINF  fprintf(stderr, "Fpu control FPPLUSINF is not supported in this machine yet.\n");
                    123: #endif
                    124: #ifndef FPTOZERO
                    125: #define  FPTOZERO  fprintf(stderr, "Fpu control FPZERO is not supported in this machine yet.\n");
                    126: #endif
                    127: #define FPCLEAR    FPNEAREST
                    128:
                    129: #define  MID_PRINTF_G  2
                    130: #define  MID_PRINTF_E  3
                    131:
1.2     ! kondoh    132: #define DEFAULTPREC    0       /* for mpfr */
        !           133:
1.1       noro      134: /* data structures */
                    135: struct oItv {
                    136:         short  id;
                    137:         char  nid;
                    138:         char  pad;
                    139:         Num  inf;
                    140:         Num  sup;
                    141: };
                    142:
                    143: typedef struct oItv *Itv;
                    144:
                    145: struct oIntervalDouble {
                    146:         short  id;
                    147:         char  nid;
                    148:         char  pad;
                    149:         double  inf;
                    150:         double  sup;
                    151: };
                    152:
                    153: typedef struct oIntervalDouble *IntervalDouble;
                    154:
                    155: struct oforth {
                    156:   short  sign;
                    157:   short  exp;
                    158:   double  u;
                    159:   double  l;
                    160: };
                    161:
                    162: typedef struct oforth *forth;
                    163:
                    164: struct oIntervalQuad {
                    165:         short  id;
                    166:         char  nid;
                    167:         char  pad;
                    168:         forth  inf;
                    169:         forth  sup;
                    170: };
                    171:
                    172: typedef struct oIntervalQuad *IntervalQuad;
                    173:
                    174: struct oIntervalBigFloat {
                    175:         short  id;
                    176:         char  nid;
                    177:         char  pad;
                    178:         BF  inf;
                    179:         BF  sup;
                    180: };
                    181:
                    182: typedef struct oIntervalBigFloat *IntervalBigFloat;
                    183:
                    184: extern int zerorewrite;
1.2     ! kondoh    185: extern int zerorewriteCount;
1.1       noro      186:
                    187: /* general macros */
                    188: #define INF(p)  ((p)->inf)
                    189: #define SUP(p)  ((p)->sup)
                    190:
                    191: #define NEWItvP(q)  ((q)=(Itv)MALLOC(sizeof(struct oItv)),\
                    192:           OID(q)=O_N,NID(q)=N_IP)
                    193: #define NEWIntervalDouble(q)  ((q)=(IntervalDouble)MALLOC(sizeof(struct oIntervalDouble)),\
                    194:           OID(q)=O_N,NID(q)=N_IntervalDouble)
                    195: #define NEWIntervalQuad(q)  ((q)=(IntervalDouble)MALLOC(sizeof(struct oIntervalQuad)),\
                    196:           OID(q)=O_N,NID(q)=N_IntervalQuad)
                    197: #define NEWIntervalBigFloat(q)  ((q)=(IntervalBigFloat)MALLOC(sizeof(struct oIntervalBigFloat)),\
                    198:           OID(q)=O_N,NID(q)=N_IntervalBigFloat)
                    199: #define MKItvP(a,b,c)  (NEWItvP(c),(INF(c)=(a),SUP(c)=(b)))
1.2     ! kondoh    200: #define MKIntervalDouble(a,b,c)  if((zerorewrite) && ((a)<=0.0) && ((b)>=0.0)) {(c)=0;zerorewriteCount++;}\
        !           201:        else (NEWIntervalDouble(c),(INF(c)=(a),SUP(c)=(b)))
1.1       noro      202: #define MKIntervalQuad(a,b,c)  (NEWIntervalQuad(c),(INF(c)=(a),SUP(c)=(b)))
                    203: #define MKIntervalBigFloat(a,b,c)  (NEWIntervalBigFloat(c),(INF(c)=(a),SUP(c)=(b)))
                    204:
                    205: #define ToItvP(a,c)  (NEWItvP(c),INF(c)=(a),SUP(c)=(a))
                    206: #define ToIntervalDouble(a,c)  (NEWIntervalDouble(c),INF(c)=(ToReal(a)),SUP(c)=(ToReal(a)))
                    207: #define ToIntervalBigFloat(a,c)  (NEWIntervalBigFloat(c),INF(c)=(a),SUP(c)=(a))
                    208:
                    209: #define ITVP(a) (NID(a)==N_IP)
                    210: #define ITVD(a) (NID(a)==N_IntervalDouble)
                    211: #define ITVQ(a) (NID(a)==N_IntervalQuad)
                    212: #define ITVF(a) (NID(a)==N_IntervalBigFloat)
                    213:
1.2     ! kondoh    214: #if 0
1.1       noro      215: double  ToRealSup(Num);
                    216: double  ToRealInf(Num);
                    217: double  RatnToRealUp(Q);
1.2     ! kondoh    218: double  NatToRealUp(N, int *);
1.1       noro      219:
                    220: void  double2bf(double, BF *);
                    221: double  bf2double(BF);
                    222:
                    223:
                    224: void    additv(Num, Num, Num *);
                    225: void    subitv(Num, Num, Num *);
                    226: void    mulitv(Num, Num, Num *);
                    227: int     initv(Num, double);
                    228: int     itvinitv(Itv, Itv);
                    229: void    divitv(Num, Num, Num *);
                    230: void    sqrtitv(Num, Num *);
                    231: void    pwritv(Num, Num, Num *);
                    232: void    pwritv0(Itv, int, Itv *);
                    233: void    chsgnitv(Num, Num *);
                    234: void    miditv(Itv, Num *);
                    235: int     cmpitv(Itv, Itv);
                    236: void    cupitv(Itv, Itv, Itv *);
                    237: void    capitv(Itv, Itv, Itv *);
                    238: void    widthitv(Itv, Num *);
                    239: void    distanceitv(Itv, Itv, Num *);
                    240: #endif
                    241:
1.2     ! kondoh    242: /***    engine/p-itv.c    ***/
        !           243: void  itvtois(Itv, Num *, Num *);
        !           244: void  istoitv(Num, Num, Itv *);
        !           245:
1.1       noro      246: void    additvp(Itv, Itv, Itv *);
                    247: void    subitvp(Itv, Itv, Itv *);
                    248: void    mulitvp(Itv, Itv, Itv *);
                    249: void    divitvp(Itv, Itv, Itv *);
1.2     ! kondoh    250: void    pwritvp(Itv, Num, Itv *);
        !           251: void    pwritv0p(Itv, int, Itv *);
1.1       noro      252: void    chsgnitvp(Itv, Itv *);
1.2     ! kondoh    253: int     initvp(Num , Itv );
        !           254: int     itvinitvp(Itv, Itv);
1.1       noro      255: int     cmpitvp(Itv, Itv);
1.2     ! kondoh    256: void miditvp(Itv, Num *);
1.1       noro      257: void    cupitvp(Itv, Itv, Itv *);
                    258: void    capitvp(Itv, Itv, Itv *);
                    259: void    widthitvp(Itv, Num *);
1.2     ! kondoh    260: void absitvp(Itv, Num *);
1.1       noro      261: void    distanceitvp(Itv, Itv, Num *);
                    262:
1.2     ! kondoh    263:
        !           264: /***    engine/f-itv.c    ***/
        !           265:
        !           266: //void  ToBf(Num, BF *);
        !           267: //void  double2bf(double, BF *);
        !           268: //double  bf2double(BF);
        !           269: //void  addulp(IntervalBigFloat, IntervalBigFloat *);
        !           270: //void  getulp(BF, BF *);
1.1       noro      271:
                    272: void    additvf(IntervalBigFloat, IntervalBigFloat, IntervalBigFloat *);
                    273: void    subitvf(IntervalBigFloat, IntervalBigFloat, IntervalBigFloat *);
                    274: void    mulitvf(IntervalBigFloat, IntervalBigFloat, IntervalBigFloat *);
                    275: void    divitvf(IntervalBigFloat, IntervalBigFloat, IntervalBigFloat *);
1.2     ! kondoh    276: void    chsgnitvf(IntervalBigFloat, IntervalBigFloat *);
        !           277: int     initvf(Num, Itv);
        !           278: int     itvinitvf(Itv, Itv);
1.1       noro      279: int     cmpitvf(Itv, Itv);
                    280: void    pwritvf(Itv, Num, Itv *);
                    281: void    pwritv0f(Itv, int, Itv *);
1.2     ! kondoh    282: void miditvf(Itv, Num *);
        !           283: void cupitvf(Itv, Itv, Itv *);
        !           284: void capitvf(Itv, Itv, Itv *);
        !           285: void widthitvf(Itv, Num *);
        !           286: void absitvf(Itv, Num *);
        !           287: void distanceitvf(Itv, Itv, Num *);
1.1       noro      288:
                    289: /***    engine/d-itv.c    ***/
                    290: double  ToRealDown(Num);
                    291: double  ToRealUp(Num);
                    292: void  Num2double(Num, double *, double *);
                    293:
                    294: void    additvd(Num, Num, IntervalDouble *);
                    295: void    subitvd(Num, Num, IntervalDouble *);
                    296: void    mulitvd(Num, Num, IntervalDouble *);
                    297: void    divitvd(Num, Num, IntervalDouble *);
                    298: void    chsgnitvd(IntervalDouble, IntervalDouble *);
1.2     ! kondoh    299: int     initvd(Num, IntervalDouble);
1.1       noro      300: int     cmpitvd(IntervalDouble, IntervalDouble);
                    301: void    pwritvd(Num, Num, IntervalDouble *);
                    302: void    pwritv0d(IntervalDouble, int, IntervalDouble *);
                    303: void    miditvd(IntervalDouble, Num *);
                    304: void    cupitvd(IntervalDouble, IntervalDouble, IntervalDouble *);
                    305: void    capitvd(IntervalDouble, IntervalDouble, IntervalDouble *);
                    306: void    widthitvd(IntervalDouble, Num *);
                    307: void    absitvd(IntervalDouble, Num *);
                    308: void    distanceitvd(IntervalDouble, IntervalDouble, Num *);
                    309:
                    310: #endif /* end of INTERVAL */
                    311: #endif /* end of _INTERVAL_H */

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