Skip to content

Commit 5c49b12

Browse files
author
Thomas Kiley
authored
Merge pull request #4823 from thk123/fix-scientific-printing
Don't add trailing dot if printing in scientific exponent
2 parents 5cade14 + a6d0e60 commit 5c49b12

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

jbmc/src/java_bytecode/expr2java.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,13 @@ std::string floating_point_to_java_string(float_type value)
7575
std::ostringstream raw_stream;
7676
raw_stream << value;
7777
const auto raw_decimal = raw_stream.str();
78-
if(raw_decimal.find('.') == std::string::npos)
78+
const bool is_scientific = raw_decimal.find('e') != std::string::npos;
79+
if(
80+
raw_decimal.find('.') == std::string::npos &&
81+
!is_scientific) // don't add trailing .0 if in scientific notation
82+
{
7983
return raw_decimal + ".0";
84+
}
8085
return raw_decimal;
8186
}();
8287
const bool is_lossless = [&] {

jbmc/unit/java_bytecode/expr2java.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,10 @@ TEST_CASE(
129129
REQUIRE(floating_point_to_java_string(-5.56268e-309) == "-5.56268e-309");
130130
#endif
131131
}
132+
133+
SECTION("Precise exponent")
134+
{
135+
REQUIRE(floating_point_to_java_string(3e+06) == "3e+06");
136+
REQUIRE(floating_point_to_java_string(3e+06f) == "3e+06f");
137+
}
132138
}

0 commit comments

Comments
 (0)