Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove Math.nextUp call in QueryConstants #5747

Merged
merged 4 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions engine/query-constants/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ plugins {
id 'java-library'
id 'io.deephaven.project.register'
}

dependencies {
testImplementation libs.junit4
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,13 @@ private QueryConstants() {}
/**
* Minimum finite value of type float.
*/
public static final float MIN_FINITE_FLOAT = Math.nextUp(-Float.MAX_VALUE);
/*
* Implemented as a constant so that it can be translated correctly to JS without needing a proper {@code
* Math.nextUp()} or {@code Math.nextAfter()} implementation that works in JavaScript. Value is generated by running
* {@code Float.toHexString(Math.nextUp(-Float.MAX_VALUE))} in jshell, and tests validate that this matches the
* expected expression.
*/
public static final float MIN_FINITE_FLOAT = -0x1.fffffcp127f;

/**
* Maximum finite value of type float.
Expand Down Expand Up @@ -241,7 +247,13 @@ private QueryConstants() {}
/**
* Minimum finite value of type double.
*/
public static final double MIN_FINITE_DOUBLE = Math.nextUp(-Double.MAX_VALUE);
/*
* Implemented as a constant so that it can be translated correctly to JS without needing a proper {@code
* Math.nextUp()} or {@code Math.nextAfter()} implementation that works in JavaScript. Value is generated by running
* {@code Double.toHexString(Math.nextUp(-Double.MAX_VALUE))} in jshell, and tests validate that this matches the
* expected expression.
*/
public static final double MIN_FINITE_DOUBLE = -0x1.ffffffffffffep1023;

/**
* Maximum finite value of type double.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.util;

import org.junit.Test;

import static org.junit.Assert.*;

public class QueryConstantsTest {

@Test
public void testMinFiniteFloat() {
final float calculated = Math.nextUp(-Float.MAX_VALUE);
// noinspection SimplifiableAssertion
assertTrue(calculated == QueryConstants.MIN_FINITE_FLOAT);
assertEquals(
Float.floatToIntBits(calculated),
Float.floatToIntBits(QueryConstants.MIN_FINITE_FLOAT));
}

@Test
public void testMinFiniteDouble() {
final double calculated = Math.nextUp(-Double.MAX_VALUE);
// noinspection SimplifiableAssertion
assertTrue(calculated == QueryConstants.MIN_FINITE_DOUBLE);
assertEquals(
Double.doubleToLongBits(calculated),
Double.doubleToLongBits(QueryConstants.MIN_FINITE_DOUBLE));
}
}
Loading