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

handle float special constant maximum #843

Merged
merged 3 commits into from
Feb 27, 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
Original file line number Diff line number Diff line change
Expand Up @@ -387,24 +387,31 @@ public static boolean isSpecialConstant(Number value, SpecialConstants constants
comparison = ((BigInteger) value)
.compareTo(SpecialConstantBitPatternTransforms.asBigInt(constants.getValidMaximum()));
} else {
Long con = SpecialConstantBitPatternTransforms.asBigInt(constants.getValidMaximum()).longValue();
Long val = value.longValue();
if (value instanceof Double) {
val = Long.valueOf(Double.doubleToRawLongBits((Double)value));
if (con.equals (val)) {
matchEdge &= true;
} else {
comparison = ((Double)value).compareTo(Double.longBitsToDouble(con));
}
} else if (value instanceof Float) {
val = Long.valueOf(Float.floatToRawIntBits((Float)value)) & 0xFFFFFFFFL;
if (con.equals (val)) {
matchEdge &= true;
if (constants.getValidMaximum().contains(".") ||
((constants.getValidMaximum().contains("e") || constants.getValidMaximum().contains("E")) &&
!(constants.getValidMaximum().startsWith("0x") || constants.getValidMaximum().startsWith("0X") || constants.getValidMaximum().startsWith("16#")))) {
comparison = Double.valueOf(value.doubleValue())
.compareTo(SpecialConstantBitPatternTransforms.asBigDecimal(constants.getValidMaximum()).doubleValue());
} else {
Long con = SpecialConstantBitPatternTransforms.asBigInt(constants.getValidMaximum()).longValue();
Long val = value.longValue();
if (value instanceof Double) {
val = Long.valueOf(Double.doubleToRawLongBits((Double)value));
if (con.equals (val)) {
matchEdge &= true;
} else {
comparison = ((Double)value).compareTo(Double.longBitsToDouble(con));
}
} else if (value instanceof Float) {
val = Long.valueOf(Float.floatToRawIntBits((Float)value)) & 0xFFFFFFFFL;
if (con.equals (val)) {
matchEdge &= true;
} else {
comparison = ((Float)value).compareTo(Float.intBitsToFloat(con.intValue()));
}
} else {
comparison = ((Float)value).compareTo(Float.intBitsToFloat(con.intValue()));
comparison = val.compareTo(con);
}
} else {
comparison = val.compareTo(con);
}
}
if (0 < comparison) {
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/features/developer.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Scenario Outline: Execute validate command for tests below.
Examples:
| testName | testDir | messageCount | messageText | problemEnum | resourceDir | reportDir | commandArgs | refOutputValue |


# Validate#823
|"NASA-PDS/validate#823 Success process problematic floats" | "github823" | 0 | "0 errors expected" | "totalErrors" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github823.json -s json --skip-context-validation -t {resourceDir}/github823/mvn_swi_l2_onboardsvymom_20230827_v02_r01.xml" | "report_github823.json" |

# Validate#785
|"NASA-PDS/validate#785 Success detecting out of range values" | "github785" | 6 | "6 warnings expected" | "FIELD_VALUE_OUT_OF_SPECIAL_CONSTANT_MIN_MAX_RANGE" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github785.json -s json --skip-context-validation -t {resourceDir}/github785/00038_FGM_RTN.xml" | "report_github785.json" |

Expand Down
Binary file not shown.
Loading
Loading