aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2018-09-04 14:03:20 +0200
committerGitHub <[email protected]>2018-09-04 14:03:20 +0200
commit8593638d1ab72a26ca85a7ef189bb8b0c2e831e8 (patch)
treecf37dcd60e7fe4ffee016ef43377fdf7d1e415e9 /erts/emulator
parent89ec9b9c09ad4af2ee9b70d6e5efdec5394b31cd (diff)
parent203ee6dcbd57c2fdbd9b9e09f0c42f7abf04dbd8 (diff)
downloadotp-8593638d1ab72a26ca85a7ef189bb8b0c2e831e8.tar.gz
otp-8593638d1ab72a26ca85a7ef189bb8b0c2e831e8.tar.bz2
otp-8593638d1ab72a26ca85a7ef189bb8b0c2e831e8.zip
Merge PR-1920 from saleyn/float_to_list OTP-15276
Fix bug in compact representation of float_to_list/2
Diffstat (limited to 'erts/emulator')
-rw-r--r--erts/emulator/sys/common/erl_sys_common_misc.c3
-rw-r--r--erts/emulator/test/num_bif_SUITE.erl1
2 files changed, 3 insertions, 1 deletions
diff --git a/erts/emulator/sys/common/erl_sys_common_misc.c b/erts/emulator/sys/common/erl_sys_common_misc.c
index 2541ab5d31..d34e1a9ec0 100644
--- a/erts/emulator/sys/common/erl_sys_common_misc.c
+++ b/erts/emulator/sys/common/erl_sys_common_misc.c
@@ -176,6 +176,7 @@ sys_double_to_chars_fast(double f, char *buffer, int buffer_size, int decimals,
double af;
Uint64 int_part, frac_part;
int neg;
+ int has_decimals = decimals != 0;
char *p = buffer;
if (decimals < 0)
@@ -257,7 +258,7 @@ sys_double_to_chars_fast(double f, char *buffer, int buffer_size, int decimals,
}
/* Delete trailing zeroes */
- if (compact)
+ if (compact && has_decimals)
p = find_first_trailing_zero(p);
*p = '\0';
return p - buffer;
diff --git a/erts/emulator/test/num_bif_SUITE.erl b/erts/emulator/test/num_bif_SUITE.erl
index 700734cd0b..f15217814a 100644
--- a/erts/emulator/test/num_bif_SUITE.erl
+++ b/erts/emulator/test/num_bif_SUITE.erl
@@ -161,6 +161,7 @@ t_float_to_string(Config) when is_list(Config) ->
test_fts("1.000",1.0, [{decimals, 3}]),
test_fts("1.0",1.0, [{decimals, 1}]),
test_fts("1.0",1.0, [{decimals, 3}, compact]),
+ test_fts("10",10.0, [{decimals, 0}, compact]),
test_fts("1.12",1.123, [{decimals, 2}]),
test_fts("1.123",1.123, [{decimals, 3}]),
test_fts("1.123",1.123, [{decimals, 3}, compact]),