|
24 | 24 | #include <m_string.h> |
25 | 25 | #include <m_ctype.h> |
26 | 26 | #include <mysql_com.h> |
27 | | -#ifdef HAVE_FCONVERT |
28 | | -#include <floatingpoint.h> |
29 | | -#endif |
30 | | - |
31 | 27 | /* |
32 | 28 | The following extern declarations are ok as these are interface functions |
33 | 29 | required by the string function |
@@ -117,82 +113,19 @@ bool String::set(ulonglong num, CHARSET_INFO *cs) |
117 | 113 |
|
118 | 114 | bool String::set(double num,uint decimals, CHARSET_INFO *cs) |
119 | 115 | { |
120 | | - char buff[331]; |
| 116 | + char buff[FLOATING_POINT_BUFFER]; |
121 | 117 | uint dummy_errors; |
| 118 | + size_t len; |
122 | 119 |
|
123 | 120 | str_charset=cs; |
124 | 121 | if (decimals >= NOT_FIXED_DEC) |
125 | 122 | { |
126 | | - uint32 len= my_sprintf(buff,(buff, "%.15g",num));// Enough for a DATETIME |
| 123 | + len= my_gcvt(num, MY_GCVT_ARG_DOUBLE, sizeof(buff) - 1, buff, NULL); |
127 | 124 | return copy(buff, len, &my_charset_latin1, cs, &dummy_errors); |
128 | 125 | } |
129 | | -#ifdef HAVE_FCONVERT |
130 | | - int decpt,sign; |
131 | | - char *pos,*to; |
132 | | - |
133 | | - (void) fconvert(num,(int) decimals,&decpt,&sign,buff+1); |
134 | | - if (!my_isdigit(&my_charset_latin1, buff[1])) |
135 | | - { // Nan or Inf |
136 | | - pos=buff+1; |
137 | | - if (sign) |
138 | | - { |
139 | | - buff[0]='-'; |
140 | | - pos=buff; |
141 | | - } |
142 | | - uint dummy_errors; |
143 | | - return copy(pos,(uint32) strlen(pos), &my_charset_latin1, cs, &dummy_errors); |
144 | | - } |
145 | | - if (alloc((uint32) ((uint32) decpt+3+decimals))) |
146 | | - return TRUE; |
147 | | - to=Ptr; |
148 | | - if (sign) |
149 | | - *to++='-'; |
150 | | - |
151 | | - pos=buff+1; |
152 | | - if (decpt < 0) |
153 | | - { /* value is < 0 */ |
154 | | - *to++='0'; |
155 | | - if (!decimals) |
156 | | - goto end; |
157 | | - *to++='.'; |
158 | | - if ((uint32) -decpt > decimals) |
159 | | - decpt= - (int) decimals; |
160 | | - decimals=(uint32) ((int) decimals+decpt); |
161 | | - while (decpt++ < 0) |
162 | | - *to++='0'; |
163 | | - } |
164 | | - else if (decpt == 0) |
165 | | - { |
166 | | - *to++= '0'; |
167 | | - if (!decimals) |
168 | | - goto end; |
169 | | - *to++='.'; |
170 | | - } |
171 | | - else |
172 | | - { |
173 | | - while (decpt-- > 0) |
174 | | - *to++= *pos++; |
175 | | - if (!decimals) |
176 | | - goto end; |
177 | | - *to++='.'; |
178 | | - } |
179 | | - while (decimals--) |
180 | | - *to++= *pos++; |
181 | | - |
182 | | -end: |
183 | | - *to=0; |
184 | | - str_length=(uint32) (to-Ptr); |
185 | | - return FALSE; |
186 | | -#else |
187 | | -#ifdef HAVE_SNPRINTF |
188 | | - buff[sizeof(buff)-1]=0; // Safety |
189 | | - snprintf(buff,sizeof(buff)-1, "%.*f",(int) decimals,num); |
190 | | -#else |
191 | | - sprintf(buff,"%.*f",(int) decimals,num); |
192 | | -#endif |
193 | | - return copy(buff,(uint32) strlen(buff), &my_charset_latin1, cs, |
| 126 | + len= my_fcvt(num, decimals, buff, NULL); |
| 127 | + return copy(buff, (uint32) len, &my_charset_latin1, cs, |
194 | 128 | &dummy_errors); |
195 | | -#endif |
196 | 129 | } |
197 | 130 |
|
198 | 131 |
|
@@ -675,7 +608,8 @@ void String::qs_append(const char *str, uint32 len) |
675 | 608 | void String::qs_append(double d) |
676 | 609 | { |
677 | 610 | char *buff = Ptr + str_length; |
678 | | - str_length+= my_sprintf(buff, (buff, "%.15g", d)); |
| 611 | + str_length+= my_gcvt(d, MY_GCVT_ARG_DOUBLE, FLOATING_POINT_BUFFER - 1, buff, |
| 612 | + NULL); |
679 | 613 | } |
680 | 614 |
|
681 | 615 | void String::qs_append(double *d) |
|
0 commit comments