summaryrefslogtreecommitdiffstats
path: root/apps/plugins/pdbox/pdbox-func.c
diff options
context:
space:
mode:
authorWincent Balin <wincent@rockbox.org>2009-08-04 02:04:24 +0000
committerWincent Balin <wincent@rockbox.org>2009-08-04 02:04:24 +0000
commit11ac0b3f2a7d2abc0ae6127752559b1ffafbebff (patch)
tree6b57fc0120b5ac8c486691be8c300709bd29f894 /apps/plugins/pdbox/pdbox-func.c
parentbec80ca7ddeff355d0ca46efa331d98c77567fd4 (diff)
downloadrockbox-11ac0b3f2a7d2abc0ae6127752559b1ffafbebff.tar.gz
rockbox-11ac0b3f2a7d2abc0ae6127752559b1ffafbebff.zip
PDBox: Minor addition and bugfixes.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22148 a1c6a512-1295-4272-9138-f99709370657
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)
strcat(out, ".");
size--;
- /* Calculate first rest and convert it. */
+ /* Calculate first rest. */
float rest1 = (f - (float) int_part) * 1000000000.0;
+
+ /* If there is no fractional part, return here. */
+ if(rest1 == 0.0f)
+ return;
+
+ /* Convert the first rest to string. */
int irest1 = (int) rest1;
snprintf(sbuf, SBUFSIZE-1, "%09d", irest1);
@@ -278,8 +284,26 @@ void rb_ftoan(float f, char* out, int size)
if(size <= 0)
return;
- /* Calculate second rest and convert it. */
+ /* Calculate second rest. */
float rest2 = (rest1 - (float) irest1) * 1000000000.0;
+
+ /* If no second rest, check whether
+ the output string has unwanted zero trail,
+ remove it and end processing here. */
+ if(rest2 == 0.0f)
+ {
+ char* zerotrail = out + strlen(out) - 1;
+
+ for(; zerotrail >= out; zerotrail--)
+ {
+ if(*zerotrail == '0')
+ *zerotrail = '\0';
+ else
+ return;
+ }
+ }
+
+ /* Convert second rest. */
int irest2 = (int) rest2;
snprintf(sbuf, SBUFSIZE-1, "%09d", irest2);
@@ -287,6 +311,16 @@ void rb_ftoan(float f, char* out, int size)
int rest2_len = strlen(sbuf);
int rest2_minlen = MIN(size, rest2_len);
strncat(out, sbuf, rest2_minlen);
+
+ /* Cut trailing zeroes. */
+ char* zerotrail = out + strlen(out) - 1;
+ for(;zerotrail >= out; zerotrail--)
+ {
+ if(*zerotrail == '0')
+ *zerotrail = '\0';
+ else
+ return;
+ }
}