Changeset 17963 for trunk/HeuristicLab.Problems.DataAnalysis
- Timestamp:
- 04/23/21 18:26:45 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs
r17911 r17963 78 78 if (double.IsNegativeInfinity(LowerBound) && double.IsPositiveInfinity(UpperBound)) return true; 79 79 if (other.LowerBound >= LowerBound && other.UpperBound <= UpperBound) return true; 80 80 81 81 return false; 82 82 } … … 97 97 /// </summary> 98 98 public bool IsPositive { 99 get => LowerBound > 0.0; 99 get => LowerBound > 0.0; 100 100 } 101 101 … … 130 130 return false; 131 131 132 return (UpperBound ==other.UpperBound || (double.IsNaN(UpperBound) && double.IsNaN(other.UpperBound)))133 && (LowerBound ==other.LowerBound || (double.IsNaN(LowerBound) && double.IsNaN(other.LowerBound)));132 return (UpperBound == other.UpperBound || (double.IsNaN(UpperBound) && double.IsNaN(other.UpperBound))) 133 && (LowerBound == other.LowerBound || (double.IsNaN(LowerBound) && double.IsNaN(other.LowerBound))); 134 134 } 135 135 … … 238 238 public static Interval Cube(Interval a) { 239 239 return new Interval(Math.Pow(a.LowerBound, 3), Math.Pow(a.UpperBound, 3)); 240 } 241 242 public static Interval Power(Interval a, int b) { 243 if (b < 0) return Power(1.0 / a, -b); // a^(-b) = 1/(a^b) 244 if (b == 0 && (a.Contains(0.0) || a.IsInfiniteOrUndefined)) return new Interval(double.NaN, double.NaN); // 0^0, +/-inf^0 are undefined 245 if (b == 0) return new Interval(1.0, 1.0); // x^0 = 1 246 if (b == 1) return a; 247 if (b % 2 == 0) { 248 // even powers (see x²) 249 if (a.UpperBound <= 0) return new Interval(Math.Pow(a.UpperBound, b), Math.Pow(a.LowerBound, b)); // interval is negative 250 if (a.LowerBound >= 0) return new Interval(Math.Pow(a.LowerBound, b), Math.Pow(a.UpperBound, b)); // interval is positive 251 return new Interval(0, Math.Max(Math.Pow(a.LowerBound, b), Math.Pow(a.UpperBound, b))); // interval goes over zero 252 } else { 253 // odd powers (see x³) 254 return new Interval(Math.Pow(a.LowerBound, b), Math.Pow(a.UpperBound, b)); 255 } 240 256 } 241 257
Note: See TracChangeset
for help on using the changeset viewer.