Skip to content

fpcmp: Allow decimal numbers ending with a period #251

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

Merged
merged 2 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 2 additions & 6 deletions tools/fpcmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,13 @@ static const char *AdvanceNumber(const char *StartPos, const char *End) {
// Decimal separator
if (Pos < End && *Pos == '.') {
++Pos;
EndOfNumber = Pos;

// Post-decimal digits (require at least one when period present)
bool HasPostDecimalDigit = false;
// Post-decimal digits (optional)
while (Pos < End && isDigitChar(*Pos)) {
HasPostDecimalDigit = true;

++Pos;
EndOfNumber = Pos;
}
if (!HasPostDecimalDigit)
return EndOfNumber;
}

// Require a valid number before the exponent.
Expand Down
8 changes: 8 additions & 0 deletions tools/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# without the source directory.
configure_file(test_not.py test_not.py
COPYONLY)
configure_file(fpcmp-input1 fpcmp-input1
COPYONLY)
configure_file(fpcmp-input2 fpcmp-input2
COPYONLY)

llvm_test_executable_no_test(ret1 ret1.c)
add_dependencies(ret1 not)
Expand All @@ -19,6 +23,10 @@ add_dependencies(abrt not)
llvm_test_run(EXECUTABLE "$<TARGET_FILE:not>" "--crash" "$<TARGET_FILE:abrt>")
llvm_add_test_for_target(abrt)

# Check that fpcmp can handle decimal numbers ending with a period correctly.
llvm_test_run(EXECUTABLE "$<TARGET_FILE:fpcmp-target>" "-a" "0.03" "-r" "0.03" "-i" "%b/test/fpcmp-input1" "%b/test/fpcmp-input2")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tolerance of 0.03 here seems fairly large. Do you expect that it will fail if it is made smaller?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

628_pop2 uses 0.03 for both absolute and relative tolerance.

# SPEC Test has both absolute and relative tolerance with same order
speccpu2017_verify_output(IGNORE_WHITESPACE ABSOLUTE_TOLERANCE 0.03 RELATIVE_TOLERANCE 0.03)

How about using a bigger value in the test file? For example: change 3.0E-02 to 1003.0E-02.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

628_pop2 uses 0.03 for both absolute and relative tolerance.

# SPEC Test has both absolute and relative tolerance with same order
speccpu2017_verify_output(IGNORE_WHITESPACE ABSOLUTE_TOLERANCE 0.03 RELATIVE_TOLERANCE 0.03)

How about using a bigger value in the test file? For example: change 3.0E-02 to 1003.0E-02.

Thanks for the clarification. Since this was motivated by 628_pop2 anyway, the tolerance is probably appropriate. There's no need for larger values.

llvm_add_test_for_target(fpcmp-target)

# Check that not passes environment variables to the called executable.
find_package(Python COMPONENTS Interpreter)
llvm_test_executable_no_test(check_env check_env.c)
Expand Down
2 changes: 2 additions & 0 deletions tools/test/fpcmp-input1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
65.
3.E-02
2 changes: 2 additions & 0 deletions tools/test/fpcmp-input2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
65.0
3.0E-02