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

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

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