summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/pdbox-func.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/pdbox-func.c')
-rw-r--r--apps/plugins/pdbox/pdbox-func.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/apps/plugins/pdbox/pdbox-func.c b/apps/plugins/pdbox/pdbox-func.c
index 22c8714b3f..c5a560de67 100644
--- a/apps/plugins/pdbox/pdbox-func.c
+++ b/apps/plugins/pdbox/pdbox-func.c
@@ -263,8 +263,14 @@ void rb_ftoan(float f, char* out, int size)
263 strcat(out, "."); 263 strcat(out, ".");
264 size--; 264 size--;
265 265
266 /* Calculate first rest and convert it. */ 266 /* Calculate first rest. */
267 float rest1 = (f - (float) int_part) * 1000000000.0; 267 float rest1 = (f - (float) int_part) * 1000000000.0;
268
269 /* If there is no fractional part, return here. */
270 if(rest1 == 0.0f)
271 return;
272
273 /* Convert the first rest to string. */
268 int irest1 = (int) rest1; 274 int irest1 = (int) rest1;
269 snprintf(sbuf, SBUFSIZE-1, "%09d", irest1); 275 snprintf(sbuf, SBUFSIZE-1, "%09d", irest1);
270 276
@@ -278,8 +284,26 @@ void rb_ftoan(float f, char* out, int size)
278 if(size <= 0) 284 if(size <= 0)
279 return; 285 return;
280 286
281 /* Calculate second rest and convert it. */ 287 /* Calculate second rest. */
282 float rest2 = (rest1 - (float) irest1) * 1000000000.0; 288 float rest2 = (rest1 - (float) irest1) * 1000000000.0;
289
290 /* If no second rest, check whether
291 the output string has unwanted zero trail,
292 remove it and end processing here. */
293 if(rest2 == 0.0f)
294 {
295 char* zerotrail = out + strlen(out) - 1;
296
297 for(; zerotrail >= out; zerotrail--)
298 {
299 if(*zerotrail == '0')
300 *zerotrail = '\0';
301 else
302 return;
303 }
304 }
305
306 /* Convert second rest. */
283 int irest2 = (int) rest2; 307 int irest2 = (int) rest2;
284 snprintf(sbuf, SBUFSIZE-1, "%09d", irest2); 308 snprintf(sbuf, SBUFSIZE-1, "%09d", irest2);
285 309
@@ -287,6 +311,16 @@ void rb_ftoan(float f, char* out, int size)
287 int rest2_len = strlen(sbuf); 311 int rest2_len = strlen(sbuf);
288 int rest2_minlen = MIN(size, rest2_len); 312 int rest2_minlen = MIN(size, rest2_len);
289 strncat(out, sbuf, rest2_minlen); 313 strncat(out, sbuf, rest2_minlen);
314
315 /* Cut trailing zeroes. */
316 char* zerotrail = out + strlen(out) - 1;
317 for(;zerotrail >= out; zerotrail--)
318 {
319 if(*zerotrail == '0')
320 *zerotrail = '\0';
321 else
322 return;
323 }
290} 324}
291 325
292 326