Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/22/20 08:48:27 (3 years ago)
Author:
gkronber
Message:

#2985: removed all usages of IsAlmost from TreeSimplifier (+ minor rearrangement of operands in unit test to match the actual output).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeSimplifier.cs

    r17180 r17797  
    933933        var constB = b as ConstantTreeNode;
    934934        var constBValue = Math.Round(constB.Value);
    935         if (constBValue.IsAlmost(1.0)) {
     935        if (constBValue == 1.0) {
    936936          return a;
    937         } else if (constBValue.IsAlmost(0.0)) {
     937        } else if (constBValue == 0.0) {
    938938          return MakeConstant(1.0);
    939         } else if (constBValue.IsAlmost(-1.0)) {
     939        } else if (constBValue == -1.0) {
    940940          return MakeFraction(MakeConstant(1.0), a);
    941941        } else if (constBValue < 0) {
     
    987987        var constB = b as ConstantTreeNode;
    988988        double exponent = Math.Round(constB.Value);
    989         if (exponent.IsAlmost(0.0)) {
     989        if (exponent == 0.0) {
    990990          return MakeConstant(1.0);
    991         } else if (exponent.IsAlmost(1.0)) {
     991        } else if (exponent == 1.0) {
    992992          return a;
    993         } else if (exponent.IsAlmost(-1.0)) {
     993        } else if (exponent == -1.0) {
    994994          return MakeFraction(MakeConstant(1.0), a);
    995995        } else if (exponent < 0) {
     
    10181018        // fold constants
    10191019        return MakeConstant(((ConstantTreeNode)a).Value / ((ConstantTreeNode)b).Value);
    1020       } else if ((IsConstant(a) && !((ConstantTreeNode)a).Value.IsAlmost(1.0))) {
     1020      } else if ((IsConstant(a) && ((ConstantTreeNode)a).Value != 1.0)) {
    10211021        return MakeFraction(MakeConstant(1.0), MakeProduct(b, Invert(a)));
    10221022      } else if (IsVariableBase(a) && IsConstant(b)) {
     
    10941094        // b is not constant => make sure constant is on the right
    10951095        return MakeSum(b, a);
    1096       } else if (IsConstant(b) && ((ConstantTreeNode)b).Value.IsAlmost(0.0)) {
     1096      } else if (IsConstant(b) && ((ConstantTreeNode)b).Value == 0.0) {
    10971097        // x + 0 => x
    10981098        return a;
     
    12101210      foreach (var unchangedSubtree in unchangedSubtrees)
    12111211        sum.AddSubtree(unchangedSubtree);
    1212       if (!constant.IsAlmost(0.0)) {
     1212      if (constant != 0.0) {
    12131213        sum.AddSubtree(MakeConstant(constant));
    12141214      }
     
    12681268        if (wi < 0) throw new ArgumentException();
    12691269        return MakeBinFactor(node1.Symbol, node1.VariableName, node1.VariableValue, node1.Weight * node0.Weights[wi]);
    1270       } else if (IsConstant(b) && ((ConstantTreeNode)b).Value.IsAlmost(1.0)) {
     1270      } else if (IsConstant(b) && ((ConstantTreeNode)b).Value == 1.0) {
    12711271        // $ * 1.0 => $
    12721272        return a;
    1273       } else if (IsConstant(b) && ((ConstantTreeNode)b).Value.IsAlmost(0.0)) {
     1273      } else if (IsConstant(b) && ((ConstantTreeNode)b).Value == 0.0) {
    12741274        return MakeConstant(0);
    12751275      } else if (IsConstant(b) && IsVariableBase(a)) {
     
    14191419        prod.AddSubtree(unchangedSubtree);
    14201420
    1421       if (!constantProduct.IsAlmost(1.0)) {
     1421      if (constantProduct != 1.0) {
    14221422        prod.AddSubtree(MakeConstant(constantProduct));
    14231423      }
Note: See TracChangeset for help on using the changeset viewer.