FAUST compiler  0.9.9.6b8
Classes | Functions
interval.hh File Reference
#include <math.h>
#include <iostream>
Include dependency graph for interval.hh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  interval
 

Functions

ostream & operator<< (ostream &dst, const interval &i)
 
double min (double x, double y)
 
double max (double x, double y)
 
double min4 (double a, double b, double c, double d)
 
double max4 (double a, double b, double c, double d)
 
interval reunion (const interval &x, const interval &y)
 
interval operator+ (const interval &x, const interval &y)
 
interval operator- (const interval &x, const interval &y)
 
interval operator* (const interval &x, const interval &y)
 
interval operator/ (const interval &x, const interval &y)
 
interval operator% (const interval &x, const interval &y)
 
int bitmask (double x)
 Convert a number 1bbb..b into a bit mask 1111..1 of same width. More...
 
interval operator& (const interval &x, const interval &y)
 
interval operator| (const interval &x, const interval &y)
 
interval operator^ (const interval &, const interval &)
 
interval operator<< (const interval &, const interval &)
 
interval operator>> (const interval &, const interval &)
 
interval operator< (const interval &, const interval &)
 
interval operator<= (const interval &, const interval &)
 
interval operator> (const interval &, const interval &)
 
interval operator>= (const interval &, const interval &)
 
interval operator== (const interval &, const interval &)
 
interval operator!= (const interval &, const interval &)
 
interval min (const interval &x, const interval &y)
 
interval max (const interval &x, const interval &y)
 
interval pow (const interval &x, const interval &y)
 
interval abs (const interval &x)
 

Function Documentation

interval abs ( const interval x)
inline

Definition at line 226 of file interval.hh.

References interval::hi, interval::lo, max(), and interval::valid.

Referenced by mterm::complexity(), AbsPrim::computeSigOutput(), http_strerror(), AbsPrim::infereSigType(), isExpPower(), and isPiPower().

227 {
228  if (x.valid) {
229  if (x.lo >= 0) {
230  return x;
231  } else if (x.hi < 0) {
232  return interval(fabs(x.hi), fabs(x.lo));
233  } else {
234  return interval(0, max(fabs(x.lo), x.hi));
235  }
236  } else {
237  return x;
238  }
239 }
bool valid
true if it is a valid interval
Definition: interval.hh:38
double lo
minimal value
Definition: interval.hh:39
double max(double x, double y)
Definition: interval.hh:60
double hi
maximal value
Definition: interval.hh:40

Here is the call graph for this function:

Here is the caller graph for this function:

int bitmask ( double  x)
inline

Convert a number 1bbb..b into a bit mask 1111..1 of same width.

Definition at line 114 of file interval.hh.

Referenced by operator&(), and operator|().

114  {
115  int v = int(x);
116  for (int i=1; i<32; i*=2) { v |= v>>i; }
117  return v;
118 }

Here is the caller graph for this function:

double max ( double  x,
double  y 
)
inline
interval max ( const interval x,
const interval y 
)
inline

Definition at line 208 of file interval.hh.

References interval::hi, interval::lo, and max().

209 {
210  return interval(max(x.lo,y.lo), max(x.hi,y.hi));
211 }
double lo
minimal value
Definition: interval.hh:39
double max(double x, double y)
Definition: interval.hh:60
double hi
maximal value
Definition: interval.hh:40

Here is the call graph for this function:

double max4 ( double  a,
double  b,
double  c,
double  d 
)
inline

Definition at line 62 of file interval.hh.

References max().

Referenced by operator*(), and pow().

62 { return max(max(a,b),max(c,d)); }
double max(double x, double y)
Definition: interval.hh:60

Here is the call graph for this function:

Here is the caller graph for this function:

double min ( double  x,
double  y 
)
inline
interval min ( const interval x,
const interval y 
)
inline

Definition at line 203 of file interval.hh.

References interval::hi, interval::lo, and min().

204 {
205  return interval(min(x.lo,y.lo), min(x.hi,y.hi));
206 }
double lo
minimal value
Definition: interval.hh:39
double min(double x, double y)
Definition: interval.hh:59
double hi
maximal value
Definition: interval.hh:40

Here is the call graph for this function:

double min4 ( double  a,
double  b,
double  c,
double  d 
)
inline

Definition at line 61 of file interval.hh.

References min().

Referenced by operator*(), and pow().

61 { return min(min(a,b),min(c,d)); }
double min(double x, double y)
Definition: interval.hh:59

Here is the call graph for this function:

Here is the caller graph for this function:

interval operator!= ( const interval ,
const interval  
)
inline

Definition at line 196 of file interval.hh.

197 {
198  return interval(0,1);
199 }
interval operator% ( const interval x,
const interval y 
)
inline

Definition at line 104 of file interval.hh.

References interval::hi, interval::lo, and interval::valid.

105 {
106  return (x.valid && y.valid && x.lo >= 0 && y.lo > 0)
107  ? interval(0,y.hi)
108  : interval();
109 }
bool valid
true if it is a valid interval
Definition: interval.hh:38
double lo
minimal value
Definition: interval.hh:39
double hi
maximal value
Definition: interval.hh:40
interval operator& ( const interval x,
const interval y 
)
inline

Definition at line 122 of file interval.hh.

References bitmask(), interval::hi, interval::lo, and interval::valid.

123 {
124  if (x.valid && y.valid) {
125  if (x.lo >= 0 & y.lo >= 0) {
126  return interval(0, bitmask(x.hi) & bitmask(y.hi));
127  } else if (y.lo >= 0) {
128  return interval(0, bitmask(y.hi));
129  } else if (x.lo >= 0) {
130  return interval(0, bitmask(y.hi));
131  } else {
132  return interval();
133  }
134  } else if (x.valid & x.lo >= 0) {
135  return interval(0, bitmask(x.hi));
136  } else if (y.valid & y.lo >= 0) {
137  return interval(0, bitmask(y.hi));
138  } else {
139  return interval();
140  }
141 }
bool valid
true if it is a valid interval
Definition: interval.hh:38
double lo
minimal value
Definition: interval.hh:39
int bitmask(double x)
Convert a number 1bbb..b into a bit mask 1111..1 of same width.
Definition: interval.hh:114
double hi
maximal value
Definition: interval.hh:40

Here is the call graph for this function:

interval operator* ( const interval x,
const interval y 
)
inline

Definition at line 84 of file interval.hh.

References interval::hi, interval::lo, max4(), min4(), and interval::valid.

85 {
86  if (x.valid&y.valid) {
87  double a=x.lo*y.lo;
88  double b=x.lo*y.hi;
89  double c=x.hi*y.lo;
90  double d=x.hi*y.hi;
91  return interval(min4(a,b,c,d), max4(a,b,c,d));
92  } else {
93  return interval();
94  }
95 }
bool valid
true if it is a valid interval
Definition: interval.hh:38
double lo
minimal value
Definition: interval.hh:39
double max4(double a, double b, double c, double d)
Definition: interval.hh:62
double min4(double a, double b, double c, double d)
Definition: interval.hh:61
double hi
maximal value
Definition: interval.hh:40

Here is the call graph for this function:

interval operator+ ( const interval x,
const interval y 
)
inline

Definition at line 74 of file interval.hh.

References interval::hi, interval::lo, and interval::valid.

75 {
76  return (x.valid&y.valid) ? interval(x.lo+y.lo, x.hi+y.hi) : interval();
77 }
bool valid
true if it is a valid interval
Definition: interval.hh:38
double lo
minimal value
Definition: interval.hh:39
double hi
maximal value
Definition: interval.hh:40
interval operator- ( const interval x,
const interval y 
)
inline

Definition at line 79 of file interval.hh.

References interval::hi, interval::lo, and interval::valid.

80 {
81  return (x.valid & y.valid) ? interval(x.lo-y.hi, x.hi-y.lo) : interval();;
82 }
bool valid
true if it is a valid interval
Definition: interval.hh:38
double lo
minimal value
Definition: interval.hh:39
double hi
maximal value
Definition: interval.hh:40
interval operator/ ( const interval x,
const interval y 
)
inline

Definition at line 97 of file interval.hh.

References interval::hi, interval::lo, and interval::valid.

98 {
99  return (x.valid && y.valid && (y.lo > 0 | y.hi < 0))
100  ? x * interval(1/y.hi,1/y.lo)
101  : interval();
102 }
bool valid
true if it is a valid interval
Definition: interval.hh:38
double lo
minimal value
Definition: interval.hh:39
double hi
maximal value
Definition: interval.hh:40
interval operator< ( const interval ,
const interval  
)
inline

Definition at line 171 of file interval.hh.

172 {
173  return interval(0,1);
174 }
ostream& operator<< ( ostream &  dst,
const interval i 
)
inline

Definition at line 50 of file interval.hh.

References interval::hi, interval::lo, and interval::valid.

51 {
52  if (i.valid) {
53  return dst << "interval(" << i.lo << ", " << i.hi << ")";
54  } else {
55  return dst << "interval()";
56  }
57 }
bool valid
true if it is a valid interval
Definition: interval.hh:38
double lo
minimal value
Definition: interval.hh:39
double hi
maximal value
Definition: interval.hh:40
interval operator<< ( const interval ,
const interval  
)
inline

Definition at line 157 of file interval.hh.

158 {
159  return interval();
160 }
interval operator<= ( const interval ,
const interval  
)
inline

Definition at line 176 of file interval.hh.

177 {
178  return interval(0,1);
179 }
interval operator== ( const interval ,
const interval  
)
inline

Definition at line 191 of file interval.hh.

192 {
193  return interval(0,1);
194 }
interval operator> ( const interval ,
const interval  
)
inline

Definition at line 181 of file interval.hh.

182 {
183  return interval(0,1);
184 }
interval operator>= ( const interval ,
const interval  
)
inline

Definition at line 186 of file interval.hh.

187 {
188  return interval(0,1);
189 }
interval operator>> ( const interval ,
const interval  
)
inline

Definition at line 162 of file interval.hh.

163 {
164  return interval();
165 }
interval operator^ ( const interval ,
const interval  
)
inline

Definition at line 152 of file interval.hh.

153 {
154  return interval();
155 }
interval operator| ( const interval x,
const interval y 
)
inline

Definition at line 143 of file interval.hh.

References bitmask(), interval::hi, interval::lo, and interval::valid.

144 {
145  if (x.valid && y.valid && x.lo >= 0 && y.lo >= 0) {
146  return interval(0, bitmask(x.hi) | bitmask(y.hi));
147  } else {
148  return interval();
149  }
150 }
bool valid
true if it is a valid interval
Definition: interval.hh:38
double lo
minimal value
Definition: interval.hh:39
int bitmask(double x)
Convert a number 1bbb..b into a bit mask 1111..1 of same width.
Definition: interval.hh:114
double hi
maximal value
Definition: interval.hh:40

Here is the call graph for this function:

interval pow ( const interval x,
const interval y 
)
inline

Definition at line 213 of file interval.hh.

References interval::hi, interval::lo, max4(), and min4().

Referenced by PowPrim::computeSigOutput(), and PowPrim::infereSigType().

214 {
215  if (x.lo > 0.0) {
216  double a = pow(x.lo,y.lo);
217  double b = pow(x.lo,y.hi);
218  double c = pow(x.hi,y.lo);
219  double d = pow(x.hi,y.hi);
220  return interval(min4(a,b,c,d), max4(a,b,c,d));
221  } else {
222  return interval();
223  }
224 }
double lo
minimal value
Definition: interval.hh:39
interval pow(const interval &x, const interval &y)
Definition: interval.hh:213
double max4(double a, double b, double c, double d)
Definition: interval.hh:62
double min4(double a, double b, double c, double d)
Definition: interval.hh:61
double hi
maximal value
Definition: interval.hh:40

Here is the call graph for this function:

Here is the caller graph for this function:

interval reunion ( const interval x,
const interval y 
)
inline

Definition at line 64 of file interval.hh.

References interval::hi, interval::lo, max(), min(), and interval::valid.

Referenced by infereSigType(), and operator|().

65 {
66  if (x.valid & y.valid) {
67  return interval(min(x.lo,y.lo), max(x.hi,y.hi));
68  } else {
69  return interval();
70  }
71 }
bool valid
true if it is a valid interval
Definition: interval.hh:38
double lo
minimal value
Definition: interval.hh:39
double max(double x, double y)
Definition: interval.hh:60
double min(double x, double y)
Definition: interval.hh:59
double hi
maximal value
Definition: interval.hh:40

Here is the call graph for this function:

Here is the caller graph for this function: