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

Annotation of OpenXM_contrib2/asir2000/include/interval.h, Revision 1.15

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

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