blob: 01d423abdb524aa6123e0534182ddb2eb6bcd7d6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
#ifndef SCRIPTSHARED_H
#define SCRIPTSHARED_H
#include <cmath>
#define eps 1e-6
typedef union _Udata{//data union
int i;float r;unsigned long d;
_Udata(){d=0;}
}Udata;
typedef struct _Idata{//data union, with type tag and operators
_Udata D;
int type;//0=int, 1=float
_Idata(){D.d=0;type=0;}
_Idata(int _type,int _data)
{type=_type;if(type==0)D.i=_data;else D.r=(float)_data;}
float &r(){return D.r;}
int &i(){return D.i;}
unsigned long &d(){return D.d;}
_Idata operator =(_Idata r)
{
if(type==1&&r.type==0)this->r()=(float)r.i();
else if(type==0&&r.type==1)this->i()=(int)r.r();
else this->d()=r.d();
return *this;
}
_Idata operator +=(_Idata r)
{
if(type==1&&r.type==0)this->r()+=(float)r.i();
if(type==0&&r.type==1)this->i()+=(int)r.r();
if(type==0&&r.type==0)this->i()+=r.i();
if(type==1&&r.type==1)this->r()+=r.r();
return *this;
}
_Idata operator -=(_Idata r)
{
if(type==1&&r.type==0)this->r()-=(float)r.i();
if(type==0&&r.type==1)this->i()-=(int)r.r();
if(type==0&&r.type==0)this->i()-=r.i();
if(type==1&&r.type==1)this->r()-=r.r();
return *this;
}
_Idata operator *=(_Idata r)
{
if(type==1&&r.type==0)this->r()*=(float)r.i();
if(type==0&&r.type==1)this->i()*=(int)r.r();
if(type==0&&r.type==0)this->i()*=r.i();
if(type==1&&r.type==1)this->r()*=r.r();
return *this;
}
_Idata operator /=(_Idata r)
{
if(type==1&&r.type==0)this->r()/=(float)r.i();
if(type==0&&r.type==1)this->i()/=(int)r.r();
if(type==0&&r.type==0)this->i()/=r.i();
if(type==1&&r.type==1)this->r()/=r.r();
return *this;
}
_Idata operator %=(_Idata r)
{
if(type==1&&r.type==0)throw;
if(type==0&&r.type==1)throw;
if(type==0&&r.type==0)this->i()%=r.i();
if(type==1&&r.type==1)throw;
return *this;
}
_Idata operator &=(_Idata r)
{
if(type==1&&r.type==0)throw;
if(type==0&&r.type==1)throw;
if(type==0&&r.type==0)this->i()&=r.i();
if(type==1&&r.type==1)throw;
return *this;
}
_Idata operator |=(_Idata r)
{
if(type==1&&r.type==0)throw;
if(type==0&&r.type==1)throw;
if(type==0&&r.type==0)this->i()|=r.i();
if(type==1&&r.type==1)throw;
return *this;
}
_Idata operator ^=(_Idata r)
{
if(type==1&&r.type==0)throw;
if(type==0&&r.type==1)throw;
if(type==0&&r.type==0)this->i()^=r.i();
if(type==1&&r.type==1)throw;
return *this;
}
_Idata operator ~()
{
if(type==1)throw;
if(type==0)i()=~i();
return *this;
}
_Idata operator ++()
{
if(type==1)throw;
if(type==0)i()=i()+1;
return *this;
}
_Idata operator --()
{
if(type==1)throw;
if(type==0)i()=i()-1;
return *this;
}
bool ltz()
{
if(type==0)return i()<0;
if(type==1)return fabs(r())>eps&&r()<0;
throw;
}
bool elz()
{
if(type==0)return i()<=0;
if(type==1)return fabs(r())<eps||(fabs(r())>eps&&r()<0);
throw;
}
bool gtz()
{
if(type==0)return i()>0;
if(type==1)return fabs(r())>eps&&r()>0;
throw;
}
bool egz()
{
if(type==0)return i()>=0;
if(type==1)return fabs(r())<eps||(fabs(r())>eps&&r()>0);
throw;
}
bool eqz()
{
if(type==0)return i()==0;
if(type==1)return fabs(r())<eps;
throw;
}
bool nez()
{
if(type==0)return i()!=0;
if(type==1)return fabs(r())>eps;
throw;
}
}Idata;
typedef struct _SPara{Udata data;int type;char *fnc;}SPara;//parameters
typedef struct _SInst//instructions
{
int id;
SPara para1,para2;
}SInst;
#endif
|