absyntax_utils/absyntax_utils.cc
changeset 568 5f79478142d7
parent 567 e5deeb6d4d2f
child 571 97b85630e496
equal deleted inserted replaced
567:e5deeb6d4d2f 568:5f79478142d7
   136 }
   136 }
   137 
   137 
   138 
   138 
   139 /* extract the value of a real from an real_c object !! */
   139 /* extract the value of a real from an real_c object !! */
   140 /* NOTE: it must ignore underscores! */
   140 /* NOTE: it must ignore underscores! */
   141 double extract_real_value(symbol_c *sym) {
   141 real64_t extract_real_value(symbol_c *sym) {
   142   std::string str = "";
   142   std::string str = "";
   143   char *endptr;
   143   char *endptr;
   144   real_c * real_sym;
   144   real_c * real_sym;
   145   uint64_t ret;
   145   uint64_t ret;
   146 
   146 
   147   if ((real_sym = dynamic_cast<real_c *>(sym)) == NULL) ERROR;
   147   if ((real_sym = dynamic_cast<real_c *>(sym)) == NULL) ERROR;
   148   for(unsigned int i = 3; i < strlen(real_sym->value); i++)
   148   for(unsigned int i = 3; i < strlen(real_sym->value); i++)
   149     if (real_sym->value[i] != '_') str += real_sym->value[i];
   149     if (real_sym->value[i] != '_') str += real_sym->value[i];
   150     
   150     
   151   ret = strtod(str.c_str(), NULL);
   151   #if    (real64_t  == float)
       
   152     ret = strtof(str.c_str(), NULL);
       
   153   #elif  (real64_t  == double)
       
   154     ret = strtod(str.c_str(), NULL);
       
   155   #elif  (real64_t  == long_double)
       
   156     ret = strtold(str.c_str(), NULL);
       
   157   #else 
       
   158     #error Could not determine which data type is being used for real64_t (defined in absyntax.hh). Aborting!
       
   159   #endif
   152   if (errno != 0) ERROR;
   160   if (errno != 0) ERROR;
   153 
   161 
   154   return ret;
   162   return ret;
   155 }
   163 }
   156 
   164