Line | |
---|
1 | using System;
|
---|
2 | // ReSharper disable CompareOfFloatsByEqualityOperator
|
---|
3 |
|
---|
4 | namespace 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.