MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / 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 < NOT_FIXED_DEC && 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= end - src;
110
111 if (sign)
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 2

process_dbl_argFunction · 0.85
set_realMethod · 0.85

Calls 2

dtoaFunction · 0.85
dtoa_freeFunction · 0.85

Tested by

no test coverage detected