[grisbi-cvs] [SCM] grisbi branch, master, updated. upstream_version_0_7_4-48-ga19b5c8

Pierre Biava nobody at users.sourceforge.net
Sat Oct 23 23:47:58 CEST 2010


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "grisbi".

The branch, master has been updated
       via  a19b5c801f066214f2c7db98694bebb8180e4db5 (commit)
       via  1262fcc9b0a6953a6c76a917c72df46056b15a63 (commit)
       via  10125692bdf3a4aafb9948f9a4f144acc72e2b3d (commit)
       via  e5e4b99af41bfeeb8c1bc4437ca6746a906761db (commit)
      from  33fde8fb5f575baf516949c04ba75cf459348697 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit a19b5c801f066214f2c7db98694bebb8180e4db5
Author: pbiava <pierre.biava at nerim.net>
Date:   Sat Oct 23 23:46:55 2010 +0200

    bugfix in managing the thousands separator and minor corrections

commit 1262fcc9b0a6953a6c76a917c72df46056b15a63
Author: pbiava <pierre.biava at nerim.net>
Date:   Sat Oct 23 23:45:09 2010 +0200

    Modified CUnit tests to reflect the changing of gsb_real.

commit 10125692bdf3a4aafb9948f9a4f144acc72e2b3d
Author: pbiava <pierre.biava at nerim.net>
Date:   Sat Oct 23 20:48:17 2010 +0200

    Adding tests for gsb_real_adjust_exponent (void)

commit e5e4b99af41bfeeb8c1bc4437ca6746a906761db
Author: pbiava <pierre.biava at nerim.net>
Date:   Sat Oct 23 20:39:32 2010 +0200

    fixed bug 1189: the check number does not decrement

-----------------------------------------------------------------------

Changes:
diff --git a/src/gsb_real.c b/src/gsb_real.c
index ce98b8c..e056fcb 100644
--- a/src/gsb_real.c
+++ b/src/gsb_real.c
@@ -62,6 +62,15 @@ lldiv_t lldiv(long long numerator, long long denominator)
 	result.rem = numerator % denominator;
 	return result;
 }
+
+long long llabs ( long long number )
+{
+    if ( number < 0 )
+        number = number * -1;
+    return number;
+}
+
+
 #define lrint(x) (floor(x + 0.5))
 #define rint(x) (floor(x + 0.5))
 #endif /*_MSC_VER */
@@ -166,6 +175,7 @@ gchar *gsb_real_raw_format_string (gsb_real number,
         gchar *mon_thousands_sep;
 
         mon_thousands_sep = g_locale_to_utf8 ( conv->mon_thousands_sep, -1, NULL, NULL, NULL );
+
         result = gsb_real_add_thousands_sep ( result, mon_thousands_sep );
 
         g_free ( mon_thousands_sep );
@@ -186,7 +196,6 @@ gchar *gsb_real_raw_format_string (gsb_real number,
                             cs_end_space,
                             cs_end );
 
-
     return result;
 }
 
@@ -657,28 +666,46 @@ gsb_real gsb_real_abs ( gsb_real number )
 gsb_real gsb_real_adjust_exponent ( gsb_real number,
                         gint return_exponent )
 {
-    gdouble tmp;
+    gint exponent;
 
     if (return_exponent == -1)
-	return number;
+        return number;
 
-    tmp = number.mantissa;
+    if ( number.exponent == return_exponent )
+        return number;
 
-    while ( number.exponent != return_exponent )
-    {
-	if (number.exponent < return_exponent)
+/*    printf ("\nnumber.mantissa = %"G_GINT64_MODIFIER"d number.exponent = %d return_exponent = %d\n",
+                number.mantissa, number.exponent, return_exponent);
+*/
+    exponent = abs ( number.exponent - return_exponent );
+/*
+    printf ("exponent = %d gsb_real_power_10[exponent] = %ld\n", exponent, gsb_real_power_10[exponent] );
+*/
+	if ( number.exponent < return_exponent )
 	{
-	    tmp = tmp * 10;
-	    number.exponent++;
+        number.mantissa = number.mantissa * gsb_real_power_10[exponent];
+        number.exponent = return_exponent;
 	}
 	else
 	{
-	    tmp = tmp / 10;
-	    number.exponent--;
-	}
-    }
-    number.mantissa = llrint ( tmp );
+        lldiv_t tmp_num;
+        gint sign;
 
+        sign = ( number.mantissa < 0 ) ? -1 : 1;
+
+        tmp_num = lldiv ( llabs ( number.mantissa ), gsb_real_power_10[exponent] );
+        
+        if ( tmp_num.rem > ( 0.5 * gsb_real_power_10[exponent] ) )
+            number.mantissa = ( tmp_num.quot + 1 ) * sign;
+        else
+            number.mantissa = tmp_num.quot * sign;
+
+        number.exponent = return_exponent;
+    }
+/*
+    printf ("number.mantissa = %"G_GINT64_MODIFIER"d number.exponent = %d\n",
+                number.mantissa, number.exponent);
+*/
     return number;
 }
 
@@ -1069,19 +1096,27 @@ gdouble gsb_real_real_to_double ( gsb_real number )
  * */
 gchar *gsb_real_add_thousands_sep ( gchar *str_number, const gchar *thousands_sep )
 {
+    gchar *mon_thousands_sep;
     gchar *result = NULL;
     gchar *ptr;
     gchar *dest;
     gchar *tmp_ptr;
+    gchar **tab_str = NULL;
     gint nbre_char;
     gint i = 0;
     gint j = 0;
     gint sep = 0;
+    gint longueur;
 
     nbre_char = strlen ( str_number );
     str_number = g_strreverse ( str_number );
     ptr = str_number;
 
+    if ( ( longueur = strlen ( thousands_sep ) ) == 1 )
+        mon_thousands_sep = g_strndup ( thousands_sep, 1 );
+    else
+        mon_thousands_sep = g_strndup ( "&", 1 );
+
     dest = g_malloc0 ( 128 * sizeof ( gchar ) );
     tmp_ptr = dest;
 
@@ -1095,7 +1130,7 @@ gchar *gsb_real_add_thousands_sep ( gchar *str_number, const gchar *thousands_se
         j++;
         if ( i < nbre_char && j == 3 )
         {
-            tmp_ptr = g_stpcpy ( tmp_ptr, thousands_sep );
+            tmp_ptr = g_stpcpy ( tmp_ptr, mon_thousands_sep );
             j = 0;
             sep++;
         }
@@ -1104,6 +1139,16 @@ gchar *gsb_real_add_thousands_sep ( gchar *str_number, const gchar *thousands_se
     result = g_strndup ( dest, nbre_char + sep );
     result = g_strreverse ( result );
 
+    /* on met le bon séparateur si necessaire */
+    if ( longueur > 1 )
+    {
+        tab_str = g_strsplit ( result, "&", 0 );
+        g_free ( result );
+
+        result = g_strjoinv ( thousands_sep, tab_str );
+        g_strfreev ( tab_str );
+    }
+
     g_free ( str_number );
     g_free ( dest );
     
diff --git a/src/tests/gsb_real_cunit.c b/src/tests/gsb_real_cunit.c
index 651f7d5..c564aa5 100644
--- a/src/tests/gsb_real_cunit.c
+++ b/src/tests/gsb_real_cunit.c
@@ -45,6 +45,7 @@ static void gsb_real_cunit__gsb_real_raw_format_string ( void );
 static void gsb_real_cunit__gsb_real_raw_get_from_string();
 static void gsb_real_cunit__gsb_real_raw_get_from_string__locale();
 static void gsb_real_cunit__gsb_real_sub();
+static void gsb_real_cunit__gsb_real_adjust_exponent ( void );
 static int gsb_real_cunit_clean_suite ( void );
 static int gsb_real_cunit_init_suite ( void );
 /* END_STATIC */
@@ -433,22 +434,22 @@ void gsb_real_cunit__gsb_real_raw_format_string ( void )
     CU_ASSERT_STRING_EQUAL("<+>21< >474< >836<.>47<€>", s);
     g_free(s);
 
-    n.mantissa = 0x80000001;
+    n.mantissa = -2147483649;
     n.exponent = 0;
     s = gsb_real_raw_format_string(n, &conv, currency_symbol);
-    CU_ASSERT_STRING_EQUAL("<->2< >147< >483< >647<.>0<€>", s);
+    CU_ASSERT_STRING_EQUAL("<->2< >147< >483< >649<.>0<€>", s);
     g_free(s);
 
-    n.mantissa = 0x80000001;
+    n.mantissa = -2147483649;
     n.exponent = 1;
     s = gsb_real_raw_format_string(n, &conv, currency_symbol);
-    CU_ASSERT_STRING_EQUAL("<->214< >748< >364<.>7<€>", s);
+    CU_ASSERT_STRING_EQUAL("<->214< >748< >364<.>9<€>", s);
     g_free(s);
 
-    n.mantissa = 0x80000001;
+    n.mantissa = -2147483649;
     n.exponent = 2;
     s = gsb_real_raw_format_string(n, &conv, currency_symbol);
-    CU_ASSERT_STRING_EQUAL("<->21< >474< >836<.>47<€>", s);
+    CU_ASSERT_STRING_EQUAL("<->21< >474< >836<.>49<€>", s);
     g_free(s);
 
     /* TODO do this test for gsb_real_format_string instead
@@ -665,6 +666,24 @@ void gsb_real_cunit__gsb_real_mul()
     CU_ASSERT_EQUAL ( 0, r.exponent );
 }
 
+
+void gsb_real_cunit__gsb_real_adjust_exponent ( void )
+{
+    gsb_real a = {1, 0};
+    gint b = 4;
+    gsb_real r = gsb_real_adjust_exponent ( a, b );
+    CU_ASSERT_EQUAL(10000, r.mantissa);
+    CU_ASSERT_EQUAL(4, r.exponent);
+
+    a.mantissa = -11926672494897;
+    a.exponent = 9;
+    b = 2;
+    r = gsb_real_adjust_exponent ( a, b );
+    CU_ASSERT_EQUAL(-1192667, r.mantissa);
+    CU_ASSERT_EQUAL(2, r.exponent);
+}
+
+
 CU_pSuite gsb_real_cunit_create_suite ( void )
 {
     CU_pSuite pSuite = CU_add_suite("gsb_real",
@@ -676,11 +695,12 @@ CU_pSuite gsb_real_cunit_create_suite ( void )
     if ( ( NULL == CU_add_test( pSuite, "of gsb_real_get_from_string()",     gsb_real_cunit__gsb_real_get_from_string ) )
       || ( NULL == CU_add_test( pSuite, "of gsb_real_raw_get_from_string()", gsb_real_cunit__gsb_real_raw_get_from_string ) )
       || ( NULL == CU_add_test( pSuite, "of gsb_real_raw_get_from_string() with locale", gsb_real_cunit__gsb_real_raw_get_from_string__locale ) )
-/*       || ( NULL == CU_add_test( pSuite, "of gsb_real_raw_format_string()",   gsb_real_cunit__gsb_real_raw_format_string ) )  */
+      || ( NULL == CU_add_test( pSuite, "of gsb_real_raw_format_string()",   gsb_real_cunit__gsb_real_raw_format_string ) )
       || ( NULL == CU_add_test( pSuite, "of gsb_real_gsb_real_normalize()",  gsb_real_cunit__gsb_real_normalize ) )
       || ( NULL == CU_add_test( pSuite, "of gsb_real_add()",                 gsb_real_cunit__gsb_real_add ) )
       || ( NULL == CU_add_test( pSuite, "of gsb_real_sub()",                 gsb_real_cunit__gsb_real_sub ) )
       || ( NULL == CU_add_test( pSuite, "of gsb_real_mul()",                 gsb_real_cunit__gsb_real_mul ) )
+      || ( NULL == CU_add_test( pSuite, "of gsb_real_adjust_exponent()",     gsb_real_cunit__gsb_real_adjust_exponent ) )
        )
         return NULL;
 
diff --git a/src/tests/main_cunit.c b/src/tests/main_cunit.c
index 31b0cc1..e636a7f 100644
--- a/src/tests/main_cunit.c
+++ b/src/tests/main_cunit.c
@@ -84,7 +84,7 @@ int gsb_cunit_run_tests()
 #ifdef _WIN32
     CU_automated_run_tests();
 #else /* _WIN32 */
-/*     CU_basic_set_mode(CU_BRM_VERBOSE);  */
+    CU_basic_set_mode(CU_BRM_VERBOSE);
     CU_basic_run_tests();
 #endif /* _WIN32 */
     CU_cleanup_registry();
diff --git a/src/utils_editables.c b/src/utils_editables.c
index 5e339a9..b723dee 100644
--- a/src/utils_editables.c
+++ b/src/utils_editables.c
@@ -125,7 +125,7 @@ void increment_decrement_champ ( GtkWidget *entry, gint increment )
 {
 	gchar* tmpstr;
 
-    tmpstr = utils_str_incremente_number_from_str ( gtk_entry_get_text ( GTK_ENTRY ( entry ) ), 1 );
+    tmpstr = utils_str_incremente_number_from_str ( gtk_entry_get_text ( GTK_ENTRY ( entry ) ), increment );
     gtk_entry_set_text ( GTK_ENTRY ( entry ), tmpstr );
 
     g_free ( tmpstr );


hooks/post-receive
-- 
grisbi


More information about the cvs mailing list