aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/sys/unix/sys_float.c
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <[email protected]>2013-01-23 17:03:41 +0100
committerBjörn-Egil Dahlberg <[email protected]>2013-01-23 17:03:41 +0100
commitd5bc1c71f756114d3110328d57e4f0545e144577 (patch)
tree11c95b7af28a060cffda5733d3043ffea707e798 /erts/emulator/sys/unix/sys_float.c
parent4c97cddddbe7c193953dbb58c342069330e3324c (diff)
parentab27e8699ef2a2bafe574158200993f184de3dc2 (diff)
downloadotp-d5bc1c71f756114d3110328d57e4f0545e144577.tar.gz
otp-d5bc1c71f756114d3110328d57e4f0545e144577.tar.bz2
otp-d5bc1c71f756114d3110328d57e4f0545e144577.zip
Merge branch 'sal/float_to_list_2/OTP-10752'
* sal/float_to_list_2/OTP-10752: Text representation of a float formatted using given options.
Diffstat (limited to 'erts/emulator/sys/unix/sys_float.c')
-rw-r--r--erts/emulator/sys/unix/sys_float.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/erts/emulator/sys/unix/sys_float.c b/erts/emulator/sys/unix/sys_float.c
index 3fcb4d88dc..6875c17a75 100644
--- a/erts/emulator/sys/unix/sys_float.c
+++ b/erts/emulator/sys/unix/sys_float.c
@@ -735,7 +735,7 @@ void erts_sys_unblock_fpe(int unmasked)
/*
** Convert a double to ascii format 0.dddde[+|-]ddd
- ** return number of characters converted
+ ** return number of characters converted or -1 if error.
**
** These two functions should maybe use localeconv() to pick up
** the current radix character, but since it is uncertain how
@@ -745,11 +745,12 @@ void erts_sys_unblock_fpe(int unmasked)
*/
int
-sys_double_to_chars(double fp, char *buffer, size_t buffer_size)
+sys_double_to_chars_ext(double fp, char *buffer, size_t buffer_size, size_t decimals)
{
char *s = buffer;
-
- (void) erts_snprintf(buffer, buffer_size, "%.20e", fp);
+
+ if (erts_snprintf(buffer, buffer_size, "%.*e", decimals, fp) >= buffer_size)
+ return -1;
/* Search upto decimal point */
if (*s == '+' || *s == '-') s++;
while (ISDIGIT(*s)) s++;