Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Problems.ProgramSynthesis/Push.Base/Extensions/MathExtensions.cs

Last change on this file was 15771, checked in by bburlacu, 7 years ago

#2895: Add solution skeleton for PushGP with genealogy analysis.

File size: 1.0 KB
Line 
1using System;
2// ReSharper disable CompareOfFloatsByEqualityOperator
3
4namespace HeuristicLab.Problems.ProgramSynthesis {
5  public static class MathExtensions {
6
7    public static long AbsoluteDiff(this long a, long b) {
8      var diff = a - b;
9
10      return diff == long.MinValue
11        ? long.MaxValue
12        : Math.Abs(diff);
13    }
14
15    public static long AbsoluteDiff(this int a, long b) {
16      return AbsoluteDiff((long)a, b);
17    }
18
19    public static int AbsoluteDiff(this int a, int b) {
20      var diff = a - b;
21
22      return diff == int.MinValue
23        ? int.MaxValue
24        : Math.Abs(diff);
25    }
26
27    public static double AbsoluteDiff(this double a, double b) {
28      var diff = a - b;
29
30      return diff == double.MinValue || double.IsNaN(diff) || double.IsInfinity(diff)
31        ? double.MaxValue
32        : Math.Abs(diff);
33    }
34
35    public static int AbsoluteDiff(this char a, char b) {
36      var diff = a - b;
37
38      return diff == int.MinValue
39        ? int.MaxValue
40        : Math.Abs(diff);
41    }
42  }
43}
Note: See TracBrowser for help on using the repository browser.