Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17300


Ignore:
Timestamp:
10/03/19 10:27:12 (5 years ago)
Author:
chaider
Message:

#2971: Fixed calculation of cubic roots (negative numbers)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs

    r17210 r17300  
    3838
    3939    public Interval(double lowerBound, double upperBound) {
    40       //TODO Handle floating point issues where lowerbound is bigger than upperbound in the nth decimal place 
     40      //TODO Handle floating point issues where lowerbound is bigger than upperbound in the nth decimal place
    4141      if (lowerBound > upperBound)
    4242        throw new ArgumentException("lowerBound must be smaller than or equal to upperBound.");
     
    264264
    265265    public static Interval CubicRoot(Interval a) {
    266       if (a.LowerBound < 0) return new Interval(double.NaN, double.NaN);
    267       return new Interval(Math.Pow(a.LowerBound, 1.0/3), Math.Pow(a.UpperBound, 1.0/3));
     266      var lower = (a.LowerBound < 0) ? -Math.Pow(-a.LowerBound, 1d / 3d) : Math.Pow(a.LowerBound, 1d / 3d);
     267      var upper = (a.UpperBound < 0) ? -Math.Pow(-a.UpperBound, 1d / 3d) : Math.Pow(a.UpperBound, 1d / 3d);
     268
     269      return new Interval(lower, upper);
    268270    }
    269271    #endregion
Note: See TracChangeset for help on using the changeset viewer.