ini config test is working again
authorFred T. Hamster <fred@feistymeow.org>
Sun, 8 Feb 2026 05:06:07 +0000 (00:06 -0500)
committerFred T. Hamster <fred@feistymeow.org>
Sun, 8 Feb 2026 05:06:07 +0000 (00:06 -0500)
the test exposed an insufficient size when performing double_plus operations, since we shifted the number into an int as part of truncation operation.  changed this to a long long instead, which seems to have sufficient size for our purposes.  previous result was that it was garbling the number and turning it negative as it handily overflowed 32 bits.

nucleus/library/basis/astring.cpp
nucleus/library/mathematics/math_ops.h
nucleus/library/tests_configuration/test_ini_configurator.cpp

index 3fdf4437d5ac93555f292c1a05a1de646b2f03b8..16a6e3c7057380632b11afb82409fe5373690778 100644 (file)
@@ -180,8 +180,14 @@ astring &astring::sprintf(const char *initial, ...)
   return to_return;
 }
 
+//#pragma temporary debug in astring!!!
+//#define DEBUG_STRING
+
 astring &astring::base_sprintf(const char *initial, va_list &args)
 {
+#ifdef DEBUG_STRING
+  printf("base_sprintf entry, format string is: %s\n", initial);
+#endif
   reset();
   if (!initial) return *this;  // skip null strings.
   if (!initial[0]) return *this;  // skip empty strings.
@@ -192,7 +198,7 @@ astring &astring::base_sprintf(const char *initial, va_list &args)
   // thanks for the inspiration to k&r page 156.
   for (const char *traverser = initial; *traverser; traverser++) {
 #ifdef DEBUG_STRING
-    printf("index=%d, char=%c\n", traverser - initial, *traverser);
+    printf("index=%d, char=%c\n", int(traverser - initial), *traverser);
 #endif
 
     if (*traverser != '%') {
@@ -202,7 +208,7 @@ astring &astring::base_sprintf(const char *initial, va_list &args)
     }
     traverser++; // go to the next character.
 #ifdef DEBUG_STRING
-    printf("index=%d, char=%c\n", traverser - initial, *traverser);
+    printf("index=%d, char=%c\n", int(traverser - initial), *traverser);
 #endif
     if (*traverser == '%') {
       // capture the "%%" style format specifier.
@@ -323,6 +329,8 @@ void astring::seek_modifier(const char *&traverser, char *modifier_chars)
 #endif
 }
 
+//#undef DEBUG_STRING
+
 void astring::get_type_character(const char * &traverser, va_list &args,
     astring &output_string, const char *flag_chars, const char *width_chars,
     const char *precision_chars, const char *modifier_chars)
index b2f7f87939c575c6961bb10278187e782f78014b..a449e326cfcafc49ebaf8fcfb24ba799f8d3e583 100644 (file)
@@ -24,19 +24,21 @@ namespace mathematics {
 class math_ops
 {
 public:
+  typedef signed long long fat_int;
+
   //! returns the rounded integer value for "to_round".
-  static int round_it(float to_round)
+  static fat_int round_it(float to_round)
   {
-    int to_return = int(to_round);
+    fat_int to_return = fat_int(to_round);
     // this uses a simplistic view of rounding.
     if (to_round - float(to_return) > 0.5) to_return++;
     return to_return;
   }
 
   //! returns the rounded integer value for "to_round".
-  static int round_it(double to_round)
+  static fat_int round_it(double to_round)
   {
-    int to_return = int(to_round);
+    fat_int to_return = fat_int(to_round);
     // this uses a simplistic view of rounding.
     if (to_round - double(to_return) > 0.5) to_return++;
     return to_return;
index 344cbce31f2211086f801356fdfb09057956506f..184204a8af797dd92e86bdc59450ae1c7e9d6a91 100644 (file)
@@ -36,6 +36,8 @@ const int test_iterations = 10;
 
 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
 
+#define UNWANTED_DEFAULT_VALUE 9949494.3
+
 HOOPLE_STARTUP_CODE;
 
 using namespace basis;
@@ -54,6 +56,8 @@ const char *INI_SECTION = "t_ini_configurator";
 //hmmm: ugly old main() without using the hoople machinery.  ack.
 astring static_class_name() { return "test_ini_configurator"; }
 
+#define MACRO_AS_STRING(s) #s
+
 int main(int formal(argc), char *formal(argv)[])
 {
   FUNCDEF("test ini config main")
@@ -115,9 +119,9 @@ LOG(astring("exe directory is currently: ") + application_configuration::applica
       frunkle def_frunkle(3.14159265358);
       astring def_text(astring::SPRINTF, "%f", def_frunkle.value());
       ini.store(INI_SECTION, TEST_NAME, def_text);
-      astring found_string = ini.load(INI_SECTION, TEST_NAME, "9949494.3");
+      astring found_string = ini.load(INI_SECTION, TEST_NAME, MACRO_AS_STRING(UNWANTED_DEFAULT_VALUE));
       frunkle found_frunkle = found_string.convert(0.0);
-      if (found_frunkle == frunkle(9949494.3))
+      if (found_frunkle == frunkle(UNWANTED_DEFAULT_VALUE))
         deadly_error(INI_SECTION, TEST_NAME, 
            "ini_configurator load failed: default was used");
       if (found_frunkle != def_frunkle)
@@ -127,14 +131,27 @@ LOG(astring("exe directory is currently: ") + application_configuration::applica
     {
       // fourth test set.
       const char *TEST_NAME = "fourth test: frunkle";
-      frunkle def_frunkle(1487335673.1415926535834985987);
-      astring def_text(astring::SPRINTF, "%f", def_frunkle.value());
+      frunkle def_frunkle((double)1487335673.1415926535834985987);
+      astring def_text(astring::SPRINTF, "%f", def_frunkle.value());     
+LOG(astring("def text is ") + def_text);
+double comparator = 1487335673.1415926535834985987;
+LOG(a_sprintf("starting from double gets %f instead", comparator));
+
       ini.store("test", "frunkle_test", def_text);
-      astring found_string = ini.load("test", "frunkle_test", "9949494.3");
+      astring found_string = ini.load("test", "frunkle_test", MACRO_AS_STRING(UNWANTED_DEFAULT_VALUE));
+                 
+LOG(astring("found string is ") + found_string);         
+
       frunkle found_frunkle = found_string.convert(0.0);
-      if (found_frunkle == frunkle(9949494.3))
+      if (found_frunkle == frunkle(0.0))
+        deadly_error(INI_SECTION, TEST_NAME,
+           "ini_configurator load failed: float conversion failed--got zero");
+
+LOG(astring("found number ") + a_sprintf("%f", found_frunkle.value()) + " which we want to be " + a_sprintf("%f", def_frunkle.value()));
+
+      if (found_frunkle == frunkle(UNWANTED_DEFAULT_VALUE))
         deadly_error(INI_SECTION, TEST_NAME,
-           "ini_configurator load failed: wrong default was used");
+           "ini_configurator load failed: wrong unwanted default was used");
       if (found_frunkle != def_frunkle)
         deadly_error(INI_SECTION, TEST_NAME, 
            "ini_configurator load failed: saved value differed");