text: #include "utils.h"
  
  char* ltoa(long value, char *string, int radix)
  {
    char tmp[33];
    char *tp = tmp;
    long i;
    unsigned long v;
    int sign;
    char *sp;
  
    if ( string == NULL )
    {
      return 0 ;
    }
  
    if (radix > 36 || radix <= 1)
    {
      return 0 ;
    }
  
    sign = (radix == 10 && value < 0);
    if (sign)
    {
      v = -value;
    }
    else
    {
      v = (unsigned long)value;
    }
  
    while (v || tp == tmp)
    {
      i = v % radix;
      v = v / radix;
      if (i < 10)
        *tp++ = i+'0';
      else
        *tp++ = i + 'a' - 10;
    }
  
    sp = string;
  
    if (sign)
      *sp++ = '-';
    while (tp > tmp)
      *sp++ = *--tp;
    *sp = 0;
  
    return string;
  }
  
  int intToStr(int x, char str[], int d)
  {
      int i = 0;
      while (x) {
          str[i++] = (x % 10) + '0';
          x = x / 10;
      }
  
      // If number of digits required is more, then
      // add 0s at the beginning
      while (i < d)
          str[i++] = '0';
  
      reverse(str, i);
      str[i] = '\0';
      return i;
  }
  
  void reverse(char* str, int len)
  {
      int i = 0, j = len - 1, temp;
      while (i < j) {
          temp = str[i];
          str[i] = str[j];
          str[j] = temp;
          i++;
          j--;
      }
  }
  
  void ftoa(float n, char* res, int afterpoint)
  {
      // Extract integer part
      int ipart = (int)n;
  
      // Extract floating part
      float fpart = n - (float)ipart;
  
      // convert integer part to string
      int i = intToStr(ipart, res, 0);
  
      // check for display option after point
      if (afterpoint != 0) {
          res[i] = '.'; // add dot
  
          // Get the value of fraction part upto given no.
          // of points after dot. The third parameter
          // is needed to handle cases like 233.007
          fpart = fpart * pow(10, afterpoint);
  
          intToStr((int)fpart, res + i + 1, afterpoint);
      }
  }
  