1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=492566
From: Frank Heckenbach <f.heckenbach@fh-soft.de>
To: submit@bugs.debian.org
Subject: gawk: wrong string length after index and sub
Date: Sun, 27 Jul 2008 12:18:03 +0200
Package: exiftags
Version: 0.98-1.1+etch1
Severity: normal
Tags: patch
The number of decimal digits used to display GPS values is computed
wrongly. The base-10 logarithm needs to be rounded up to get the
correct number.
E.g., in an example I had n=297, d=5. Since log10(d)=0.69..., it's
rounded to 0, i.e. the fraction is displayed with no decimals (59).
Rounding up the logarithm to 1 will correctly display 1 decimal
(59.4).
Index: exiftags-1.01/exifgps.c
===================================================================
--- exiftags-1.01.orig/exifgps.c 2008-08-15 21:07:22.188558952 +0300
+++ exiftags-1.01/exifgps.c 2008-08-15 21:07:23.456543290 +0300
@@ -287,7 +287,7 @@
deg = (double)n / (double)d;
if (d != 1)
sprintf(fmt, "%%s %%.%df%%s ",
- (int)log10((double)d));
+ (int)ceil(log10((double)d)));
}
/* Minutes. */
@@ -302,7 +302,7 @@
} else {
min = (double)n / (double)d;
if (d != 1) {
- sprintf(buf, "%%.%df'", (int)log10((double)d));
+ sprintf(buf, "%%.%df'", (int)ceil(log10((double)d)));
strcat(fmt, buf);
} else
strcat(fmt, "%.f'");
@@ -324,7 +324,7 @@
} else {
sec = (double)n / (double)d;
if (d != 1) {
- sprintf(buf, " %%.%df", (int)log10((double)d));
+ sprintf(buf, " %%.%df", (int)ceil(log10((double)d)));
strcat(fmt, buf);
} else
strcat(fmt, " %.f");
@@ -369,10 +369,10 @@
if (!d) break;
if (!i)
- sprintf(fmt, "%%02.%df", (int)log10((double)d));
+ sprintf(fmt, "%%02.%df", (int)ceil(log10((double)d)));
else
sprintf(fmt, ":%%02.%df",
- (int)log10((double)d));
+ (int)ceil(log10((double)d)));
snprintf(buf, 8, fmt, (double)n / (double)d);
strcat(prop->str, buf);
|