Exemplo n.º 1
0
void test_is_dec_digit()
{
   Long x;
   CHECK( is_dec_digit('0', &x) && 0 == x );
   CHECK( is_dec_digit('1', &x) && 1 == x );
   CHECK( is_dec_digit('9', &x) && 9 == x );
}
Exemplo n.º 2
0
double VG_(strtod) ( const HChar* str, HChar** endptr )
{
   Bool neg = False;
   Long digit;
   double n = 0, frac = 0, x = 0.1;

   // Skip leading whitespace.
   while (VG_(isspace)(*str)) str++;

   // Allow a leading '-' or '+'.
   if (*str == '-') { str++; neg = True; }
   else if (*str == '+') { str++; }

   while (is_dec_digit(*str, &digit)) {
      n = 10*n + digit;
      str++;
   }

   if (*str == '.') {
      str++;
      while (is_dec_digit(*str, &digit)) {
         frac += x*digit;
         x /= 10;
         str++;
      }
   }

   n += frac;
   if (neg) n = -n;
   if (endptr) *endptr = (HChar *)str;    // Record first failing character.
   return n;
}
Exemplo n.º 3
0
Long VG_(strtoll10) ( Char* str, Char** endptr )
{
   Bool neg = False;
   Long n = 0, digit = 0;

   // Skip leading whitespace.
   while (VG_(isspace)(*str)) str++;

   // Allow a leading '-' or '+'.
   if (*str == '-') { str++; neg = True; }
   else if (*str == '+') { str++; }

   while (is_dec_digit(*str, &digit)) {
      n = 10*n + digit;
      str++;
   }

   if (neg) n = -n;
   if (endptr) *endptr = str;    // Record first failing character.
   return n;
}
Exemplo n.º 4
0
ULong VG_(strtoull10) ( const HChar* str, HChar** endptr )
{
   Bool converted = False;
   ULong n = 0;
   Long digit = 0;
   const HChar* str0 = str;

   // Skip leading whitespace.
   while (VG_(isspace)(*str)) str++;

   // Allow a leading '+'.
   if (*str == '+') { str++; }

   while (is_dec_digit(*str, &digit)) {
      converted = True;          // Ok, we've actually converted a digit.
      n = 10*n + digit;
      str++;
   }

   if (!converted) str = str0;   // If nothing converted, endptr points to
   //   the start of the string.
   if (endptr) *endptr = (HChar *)str;    // Record first failing character.
   return n;
}
Long VG_(strtoll10) ( Char* str, Char** endptr )
{
   Bool neg = False, converted = False;
   Long n = 0, digit = 0;
   Char* str0 = str;

   // Skip leading whitespace.
   while (VG_(isspace)(*str)) str++;

   // Allow a leading '-' or '+'.
   if (*str == '-') { str++; neg = True; }
   else if (*str == '+') { str++; }

   while (is_dec_digit(*str, &digit)) {
      converted = True;          // Ok, we've actually converted a digit.
      n = 10*n + digit;
      str++;
   }

   if (!converted) str = str0;   // If nothing converted, endptr points to
   if (neg) n = -n;              //   the start of the string.
   if (endptr) *endptr = str;    // Record first failing character.
   return n;
}