Example #1
0
void string_of_float_aux(char* format_buffer, double x)
{
  sprintf(format_buffer, "%.12g", x);
  mkSMLMinus(format_buffer);
  if( countChar('.', format_buffer) == 0 &&
      countChar('E', format_buffer) == 0 )
    strcat(format_buffer, ".0");
}
Example #2
0
value sml_string_of_int(value arg)
{
  char format_buffer[32];

  sprintf(format_buffer, "%ld", VAL_TO_LONG(arg));
  mkSMLMinus(format_buffer);
  return copy_string(format_buffer);
}
Example #3
0
String
REG_POLY_FUN_HDR(stringOfFloat, Region rAddr, size_t arg) 
{
  char buf[64];
  sprintf(buf, "%.12g", get_d(arg));
  mkSMLMinus(buf);
  if( countChar('.', buf) == 0 && countChar('E', buf) == 0 ) 
    {
      strcat(buf, ".0");
    }
  return REG_POLY_CALL(convertStringToML, rAddr,buf);
}
Example #4
0
String
REG_POLY_FUN_HDR(generalStringOfFloat, Region rAddr, String format, size_t f) 
{
  char result_buf[512];

  /* Unfortunately there seems to be no way to ensure that this does not
   * crash by overflowing the result_buffer (e.g. when specifying a huge 
   * number of decimal digits in the fixed-point format): 
   */
  sprintf(result_buf, &(format->data), get_d(f));
  mkSMLMinus(result_buf);
  return REG_POLY_CALL(convertStringToML, rAddr, result_buf);
}
Example #5
0
value sml_general_string_of_float(value fmt, value arg)
{
#define BUFSIZE 512
  char format_buffer[BUFSIZE];

  /* Unfortunately there seems to be no way to ensure that this does not
   * crash by overflowing the format_buffer (e.g. when specifying a huge
   * number of decimal digits in the fixed-point format).  Well, we might
   * use snprintf if universally supported?
   */

  double x = Double_val(arg);
  if (x == -0.0) x = 0.0;
  sprintf(format_buffer, String_val(fmt), x);

  mkSMLMinus(format_buffer);
  return copy_string(format_buffer);
#undef BUFSIZE
}