Opened 10 years ago

Closed 10 years ago

#720 closed defect (fixed)

G_trim_decimal(): don't chop 0s on strings ending in e+20

Reported by: hamish Owned by: grass-dev@…
Priority: critical Milestone: 6.4.0
Component: LibGIS Version: 6.4.0 RCs
Keywords: G_trim_decimal Cc:
CPU: All Platform: All

Description

Hi,

G_trim_decimal() will blindly chop away 0s after the decimal point, converting ,for example, a string ending in e+20 into e+2. :-(

I guess 'e' needs to be the trigger character; if found we have a choice to either just return the original string or perform heroics such as:

1.234567890123460000000000000000e+20
    ->
1.23456789012346e+20

?

thanks, Hamish

Change History (3)

comment:1 Changed 10 years ago by hamish

comments?

Index: lib/gis/trim_dec.c
===================================================================
--- lib/gis/trim_dec.c  (revision 38754)
+++ lib/gis/trim_dec.c  (working copy)
@@ -14,6 +14,7 @@
  * \date 1999-2008
  */
 
+#include <string.h>
 #include <grass/gis.h>
 
 
@@ -30,6 +31,10 @@
 {
     char *mark;
 
+    /* don't trim e+20 into e+2 */
+    if( strchr(buf, 'e') || strchr(buf, 'E') )
+       return 0;
+
     /* find the . */
     while (*buf != '.')
        if (*buf++ == 0)

Hamish

comment:2 Changed 10 years ago by hamish

there has been no feedback so I have applied this patch in 6.5svn and trunk. I'd like to backport it to 6.4 as well but won't without further testing.

comment:3 Changed 10 years ago by hamish

Resolution: fixed
Status: newclosed

backported to relbr64 in r39045. still no feedback, hope there are no problems with it.

Hamish

Note: See TracTickets for help on using tickets.