5 // Alexander Chebaturkin (chebaturkin@gmail.com)
7 // Copyright (C) 2012 Alexander Chebaturkin
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using Mono
.CodeContracts
.Static
.Lattices
;
31 namespace Mono
.CodeContracts
.Static
.Analysis
.Numerical
{
32 class IntervalContext
: IntervalRationalContextBase
<Interval
> {
33 public static readonly IntervalContext Instance
= new IntervalContext ();
39 public override Interval TopValue { get { return Interval.TopValue; }
}
40 public override Interval BottomValue { get { return Interval.BottomValue; }
}
42 public override Interval Zero { get { return Interval.For (Rational.Zero); }
}
43 public override Interval One { get { return Interval.For (Rational.One); }
}
45 public override Interval Positive { get { return Interval.For (0, Rational.PlusInfinity); }
}
46 public override Interval Negative { get { return Interval.For (Rational.MinusInfinity, 0); }
}
48 public override Interval GreaterEqualThanMinusOne { get { return Interval.For (Rational.MinusOne, Rational.PlusInfinity); }
}
50 public override Interval
For (long value)
52 return Interval
.For (value);
55 public override Interval
For (long lower
, long upper
)
57 return Interval
.For (lower
, upper
);
60 public override Interval
For (long lower
, Rational upper
)
62 return Interval
.For (lower
, upper
);
65 public override Interval
For (Rational lower
, long upper
)
67 return Interval
.For (lower
, upper
);
70 public override Interval
For (Rational
value)
72 return Interval
.For (value);
75 public override Interval
For (Rational lower
, Rational upper
)
77 return Interval
.For (lower
, upper
);
80 public override Interval
LeftOpen (Rational upperBound
)
82 return Interval
.For (Rational
.MinusInfinity
, upperBound
);
85 public override Interval
RightOpen (Rational lowerBound
)
87 return Interval
.For (lowerBound
, Rational
.PlusInfinity
);
90 public override Interval
Add (Interval a
, Interval b
)
95 public override Interval
Sub (Interval a
, Interval b
)
100 public override Interval
Div (Interval a
, Interval b
)
105 public override Interval
Mul (Interval a
, Interval b
)
110 public override Interval
Not (Interval
value)
112 if (!value.IsNormal ())
116 if (value.TryGetSingletonFiniteInt32 (out intValue
))
117 return Interval
.For (intValue
!= 0 ? 0 : 1);
119 return Interval
.TopValue
;
122 public override Interval
Rem (Interval a
, Interval b
)
127 public override Interval
UnaryMinus (Interval
value)
132 public override Interval
ApplyConversion (ExpressionOperator conv
, Interval intv
)
134 return Interval
.ApplyConversion (conv
, intv
);