Annotation of OpenXM_contrib2/asir2000/builtin/round.c, Revision 1.7
1.7 ! noro 1: /* $OpenXM: OpenXM_contrib2/asir2000/builtin/round.c,v 1.6 2007/01/30 00:38:25 noro Exp $ */
1.6 noro 2:
3: #undef INTERVAL
4: #define INTERVAL
1.1 noro 5: #include "ca.h"
6: #include "parse.h"
1.6 noro 7: #include "interval.h"
8:
9: void Padd_pinf(),Padd_minf();
10: void Psub_pinf(),Psub_minf();
11: void Pmul_pinf(),Pmul_minf();
12: void Pdiv_pinf(),Pdiv_minf();
1.1 noro 13:
14: struct ftab round_tab[] = {
1.7 ! noro 15: {"add_pinf",Padd_pinf,2},
! 16: {"add_minf",Padd_minf,2},
! 17: {"sub_pinf",Psub_pinf,2},
! 18: {"sub_minf",Psub_minf,2},
! 19: {"mul_pinf",Pmul_pinf,2},
! 20: {"mul_minf",Pmul_minf,2},
! 21: {"div_pinf",Pdiv_pinf,2},
! 22: {"div_minf",Pdiv_minf,2},
! 23: {0,0,0},
1.1 noro 24: };
1.6 noro 25:
26: void Padd_pinf(NODE arg,Real *rp)
27: {
1.7 ! noro 28: Real a,b,r;
! 29: double c;
1.6 noro 30:
1.7 ! noro 31: a = (Real)ARG0(arg);
! 32: b = (Real)ARG1(arg);
! 33: if ( !a )
! 34: *rp = b;
! 35: else if ( !b )
! 36: *rp = a;
! 37: else if ( NID(a) != N_R || NID(b) != N_R )
! 38: error("add_pinf : invalid argument");
! 39: else {
! 40: FPPLUSINF
! 41: c = BDY(a)+BDY(b);
! 42: FPNEAREST
! 43: MKReal(c,r);
! 44: *rp = r;
! 45: }
1.6 noro 46: }
47:
48: void Padd_minf(NODE arg,Real *rp)
49: {
1.7 ! noro 50: Real a,b,r;
! 51: double c;
1.6 noro 52:
1.7 ! noro 53: a = (Real)ARG0(arg);
! 54: b = (Real)ARG1(arg);
! 55: if ( !a )
! 56: *rp = b;
! 57: else if ( !b )
! 58: *rp = a;
! 59: else if ( NID(a) != N_R || NID(b) != N_R )
! 60: error("add_pinf : invalid argument");
! 61: else {
! 62: FPMINUSINF
! 63: c = BDY(a)+BDY(b);
! 64: FPNEAREST
! 65: MKReal(c,r);
! 66: *rp = r;
! 67: }
1.6 noro 68: }
69:
70: void Psub_pinf(NODE arg,Real *rp)
71: {
1.7 ! noro 72: Real a,b,r;
! 73: double c;
1.6 noro 74:
1.7 ! noro 75: a = (Real)ARG0(arg);
! 76: b = (Real)ARG1(arg);
! 77: if ( !a ) {
! 78: if ( !b )
! 79: *rp = 0;
! 80: else {
! 81: c = -BDY(b);
! 82: MKReal(c,r);
! 83: *rp = r;
! 84: }
! 85: } else if ( !b )
! 86: *rp = a;
! 87: else if ( NID(a) != N_R || NID(b) != N_R )
! 88: error("sub_pinf : invalid argument");
! 89: else {
! 90: FPPLUSINF
! 91: c = BDY(a)-BDY(b);
! 92: FPNEAREST
! 93: MKReal(c,r);
! 94: *rp = r;
! 95: }
1.6 noro 96: }
97:
98: void Psub_minf(NODE arg,Real *rp)
99: {
1.7 ! noro 100: Real a,b,r;
! 101: double c;
1.6 noro 102:
1.7 ! noro 103: a = (Real)ARG0(arg);
! 104: b = (Real)ARG1(arg);
! 105: if ( !a ) {
! 106: if ( !b )
! 107: *rp = 0;
! 108: else {
! 109: c = -BDY(b);
! 110: MKReal(c,r);
! 111: *rp = r;
! 112: }
! 113: } else if ( !b )
! 114: *rp = a;
! 115: else if ( NID(a) != N_R || NID(b) != N_R )
! 116: error("sub_minf : invalid argument");
! 117: else {
! 118: FPMINUSINF
! 119: c = BDY(a)-BDY(b);
! 120: FPNEAREST
! 121: MKReal(c,r);
! 122: *rp = r;
! 123: }
1.6 noro 124: }
125:
126: void Pmul_pinf(NODE arg,Real *rp)
127: {
1.7 ! noro 128: Real a,b,r;
! 129: double c;
1.6 noro 130:
1.7 ! noro 131: a = (Real)ARG0(arg);
! 132: b = (Real)ARG1(arg);
! 133: if ( !a || !b )
! 134: *rp = 0;
! 135: else if ( NID(a) != N_R || NID(b) != N_R )
! 136: error("mul_pinf : invalid argument");
! 137: else {
! 138: FPPLUSINF
! 139: c = BDY(a)*BDY(b);
! 140: FPNEAREST
! 141: MKReal(c,r);
! 142: *rp = r;
! 143: }
1.6 noro 144: }
145:
146: void Pmul_minf(NODE arg,Real *rp)
147: {
1.7 ! noro 148: Real a,b,r;
! 149: double c;
1.6 noro 150:
1.7 ! noro 151: a = (Real)ARG0(arg);
! 152: b = (Real)ARG1(arg);
! 153: if ( !a || !b )
! 154: *rp = 0;
! 155: else if ( NID(a) != N_R || NID(b) != N_R )
! 156: error("mul_minf : invalid argument");
! 157: else {
! 158: FPMINUSINF
! 159: c = BDY(a)*BDY(b);
! 160: FPNEAREST
! 161: MKReal(c,r);
! 162: *rp = r;
! 163: }
1.6 noro 164: }
165:
166: void Pdiv_pinf(NODE arg,Real *rp)
167: {
1.7 ! noro 168: Real a,b,r;
! 169: double c;
1.6 noro 170:
1.7 ! noro 171: a = (Real)ARG0(arg);
! 172: b = (Real)ARG1(arg);
! 173: if ( !b )
! 174: error("div_pinf : division by 0");
! 175: else if ( !a )
! 176: *rp = 0;
! 177: else if ( NID(a) != N_R || NID(b) != N_R )
! 178: error("div_pinf : invalid argument");
! 179: else {
! 180: FPPLUSINF
! 181: c = BDY(a)/BDY(b);
! 182: FPNEAREST
! 183: MKReal(c,r);
! 184: *rp = r;
! 185: }
1.6 noro 186: }
187:
188: void Pdiv_minf(NODE arg,Real *rp)
189: {
1.7 ! noro 190: Real a,b,r;
! 191: double c;
1.6 noro 192:
1.7 ! noro 193: a = (Real)ARG0(arg);
! 194: b = (Real)ARG1(arg);
! 195: if ( !b )
! 196: error("div_minf : division by 0");
! 197: else if ( !a )
! 198: *rp = 0;
! 199: else if ( NID(a) != N_R || NID(b) != N_R )
! 200: error("div_minf : invalid argument");
! 201: else {
! 202: FPMINUSINF
! 203: c = BDY(a)/BDY(b);
! 204: FPNEAREST
! 205: MKReal(c,r);
! 206: *rp = r;
! 207: }
1.6 noro 208: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>