Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2796_SymbReg/HeuristicLab.Algorithms.DataAnalysis/3.4/MctsSymbolicRegression/ApproximateDoubleEqualityComparer.cs @ 16752

Last change on this file since 16752 was 15606, checked in by gkronber, 7 years ago

#2796: comments and typos

File size: 772 bytes
Line 
1using System;
2using System.Collections.Generic;
3
4namespace HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression {
5  // unused?
6  internal class ApproximateDoubleEqualityComparer : IEqualityComparer<double> {
7    public bool Equals(double x, double y) {
8      // TODO: check
9      var xl = (ulong)BitConverter.DoubleToInt64Bits(x);
10      var yl = (ulong)BitConverter.DoubleToInt64Bits(y);
11
12      xl = xl & 0xFFFFFFFFFFFFFFE0; // ignore least significant bits
13      yl = yl & 0xFFFFFFFFFFFFFFE0;
14
15      return xl == yl;
16    }
17
18    public int GetHashCode(double obj) {
19      var bits = (ulong)BitConverter.DoubleToInt64Bits(obj);
20
21      bits = bits & 0xFFFFFFFFFFFFFFE0; // ignore least significant bits
22
23      return (int)bits;
24    }
25  }
26}
Note: See TracBrowser for help on using the repository browser.