thirdparty/facil.io/lib/facil/core/types/fiobj/fiobj_numbers.c
/**
 * A helper function that convers between a double to a string.
 *
 * No overflow guard is provided, make sure there's at least 130 bytes
 * available (for base 2).
 *
 * Supports base 2, base 10 and base 16. An unsupported base will silently
 * default to base 10. Prefixes aren't added (i.e., no "0x" or "0b" at the
 * beginning of the string).
 *
 * Returns the number of bytes actually written (excluding the NUL
 * terminator).
 */
A helper function that convers between a double to a string.
No overflow guard is provided, make sure there's at least 130 bytes
available (for base 2).



Returns the number of bytes actually written (excluding the NUL
terminator).
A helper function that convers between a double to a string . No overflow guard is provided make sure there ' s at least 130 bytes available ( for base 2 ) . Returns the number of bytes actually written ( excluding the NUL terminator ) .
size_t fio_ftoa(char *dest, double num, uint8_t base) {
  if (base == 2 || base == 16) {
    int64_t *i = (void *)&num;
    return fio_ltoa(dest, *i, base);
  }
  size_t written = sprintf(dest, "%g", num);
  uint8_t need_zero = 1;
  char *start = dest;
  while (*start) {
    if (*start == ',') 
      *start = '.';
    if (*start == '.' || *start == 'e') {
      need_zero = 0;
      break;
    }
    start++;
  }
  if (need_zero) {
    dest[written++] = '.';
    dest[written++] = '0';
  }
  return written;
}
size_t fio_ftoa ( char * dest , double num , uint8_t base ) { if ( base == 2 || base == 16 ) { int64_t * i = ( void * ) & num ; return fio_ltoa ( dest , * i , base ) ; } size_t written = sprintf ( dest , " " , num ) ; uint8_t need_zero = 1 ; char * start = dest ; while ( * start ) { if ( * start == ' ' ) * start = ' ' ; if ( * start == ' ' || * start == ' ' ) { need_zero = 0 ; break ; } start ++ ; } if ( need_zero ) { dest [ written ++ ] = ' ' ; dest [ written ++ ] = ' ' ; } return written ; }
A helper function that convers between a double to a string.
A helper function that convers between a double to a string .
/* handle the binary / Hex representation the same as if it were an
     * int64_t
     */ // locale issues?