Skip to content

Commit

Permalink
Be picky with double comparisons
Browse files Browse the repository at this point in the history
Co-Authored-By: Ioannis Panagiotas <[email protected]>
  • Loading branch information
jjaderberg and IoannisPanagiotas committed Oct 24, 2023
1 parent b3cbeff commit c6a49ce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected DagLongestPath(
this.nodeCount = graph.nodeCount();
this.concurrency = concurrency;
this.inDegrees = HugeAtomicLongArray.of(nodeCount, ParalleLongPageCreator.passThrough(this.concurrency));
this.parentsAndDistances = TentativeDistances.distanceAndPredecessors(nodeCount, concurrency, Double.MIN_VALUE, (a, b) -> a < b);
this.parentsAndDistances = TentativeDistances.distanceAndPredecessors(nodeCount, concurrency, Double.MIN_VALUE, (a, b) -> Double.compare(a, b) < 0);
}

@Override
Expand Down Expand Up @@ -191,9 +191,9 @@ void longestPathTraverse(long source, long target, double weight) {
// the source distance will never change anymore, but the target distance might
var potentialDistance = parentsAndDistances.distance(source) + weight;
var currentTargetDistance = parentsAndDistances.distance(target);
while(potentialDistance > currentTargetDistance) {
while (Double.compare(potentialDistance, currentTargetDistance) > 0) {
var witnessValue = parentsAndDistances.compareAndExchange(target, currentTargetDistance, potentialDistance, source);
if(currentTargetDistance == witnessValue) {
if (Double.compare(currentTargetDistance, witnessValue) == 0) {
break;
}
currentTargetDistance = parentsAndDistances.distance(target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static DistanceAndPredecessor distanceAndPredecessors(
long size,
int concurrency
) {
return distanceAndPredecessors(size, concurrency, DIST_INF, (a, b) -> a > b);
return distanceAndPredecessors(size, concurrency, DIST_INF, (a, b) -> Double.compare(a, b) > 0);
}

public static DistanceAndPredecessor distanceAndPredecessors(
Expand Down Expand Up @@ -183,7 +183,7 @@ public double compareAndExchange(long nodeId, double expectedDistance, double ne
//we should signal failure
// for that we must be sure not to return the 'expectedDistance' by accident!
//we hence return its negation (or -1 if ==0)
return (Double.compare(expectedDistance, 0.0) == 0) ? -1.0 : -expectedDistance;
return Double.compare(expectedDistance, 0.0) == 0 ? -1.0 : -expectedDistance;
}

var witness = predecessors.compareAndExchange(nodeId, currentPredecessor, -predecessor - 1);
Expand All @@ -192,7 +192,7 @@ public double compareAndExchange(long nodeId, double expectedDistance, double ne
if (witness != currentPredecessor) {
//we should signal failure
// for that we must be sure not to return the 'expectedDistance' by accident!
return (Double.compare(expectedDistance, 0.0) == 0) ? -1.0 : -expectedDistance;
return Double.compare(expectedDistance, 0.0) == 0 ? -1.0 : -expectedDistance;
}

// we have the lock; no-one else can write on nodeId at the moment.
Expand Down

0 comments on commit c6a49ce

Please sign in to comment.