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 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
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 @@ -25,3 +29,7 @@ llvm_test_executable_no_test(check_env check_env.c)
add_dependencies(check_env not)
llvm_test_run(EXECUTABLE ${Python_EXECUTABLE} "%b/test/test_not.py" "$<TARGET_FILE:not>" "$<TARGET_FILE:check_env>")
llvm_add_test_For_target(check_env)

# 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")
llvm_add_test_for_target(fpcmp-target)
8 changes: 8 additions & 0 deletions tools/test/fpcmp-input1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
65.
3.E+02
-------
45000
7E+03
-------
.9
.6E+04
8 changes: 8 additions & 0 deletions tools/test/fpcmp-input2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
65.0
300.0
-------
45000.0
7000.0
-------
0.9
6000