MCPcopy Create free account
hub / github.com/MariaDB/server / my_fcvt

Function my_fcvt

strings/dtoa.c:89–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87*/
88
89size_t my_fcvt(double x, int precision, char *to, my_bool *error)
90{
91 int decpt, sign, len, i;
92 char *res, *src, *end, *dst= to;
93 char buf[DTOA_BUFF_SIZE];
94 DBUG_ASSERT(precision >= 0 && precision < DECIMAL_NOT_SPECIFIED && to != NULL);
95
96 res= dtoa(x, 5, precision, &decpt, &sign, &end, buf, sizeof(buf));
97
98 if (decpt == DTOA_OVERFLOW)
99 {
100 dtoa_free(res, buf, sizeof(buf));
101 *to++= '0';
102 *to= '\0';
103 if (error != NULL)
104 *error= TRUE;
105 return 1;
106 }
107
108 src= res;
109 len= (int)(end - src);
110
111 if (sign && x != 0.0)
112 *dst++= '-';
113
114 if (decpt <= 0)
115 {
116 *dst++= '0';
117 *dst++= '.';
118 for (i= decpt; i < 0; i++)
119 *dst++= '0';
120 }
121
122 for (i= 1; i <= len; i++)
123 {
124 *dst++= *src++;
125 if (i == decpt && i < len)
126 *dst++= '.';
127 }
128 while (i++ <= decpt)
129 *dst++= '0';
130
131 if (precision > 0)
132 {
133 if (len <= decpt)
134 *dst++= '.';
135
136 for (i= precision - MY_MAX(0, (len - decpt)); i > 0; i--)
137 *dst++= '0';
138 }
139
140 *dst= '\0';
141 if (error != NULL)
142 *error= FALSE;
143
144 dtoa_free(res, buf, sizeof(buf));
145
146 return dst - to;

Callers 9

process_dbl_argFunction · 0.85
get_one_variableFunction · 0.85
storeMethod · 0.85
val_strMethod · 0.85
set_double_valueMethod · 0.85
add_user_optionFunction · 0.85
set_fcvtMethod · 0.85
set_real_with_typeMethod · 0.85

Calls 2

dtoaFunction · 0.85
dtoa_freeFunction · 0.85

Tested by

no test coverage detected