コード例 #1
0
DFP_C_TYPE
BFP_TO_DFP (BFP_TYPE x)
{
  DFP_C_TYPE f;
  IEEE_TYPE s;
  char buf[BUFMAX];
  decContext context;

  decContextDefault (&context, CONTEXT_INIT);
  context.round = CONTEXT_ROUND;

  /* Use a C library function to write the floating point value to a string.  */
#ifdef BFP_VIA_TYPE
  /* FIXME: Is there a better way to output an XFmode variable in C?  */
  sprintf (buf, BFP_FMT, (BFP_VIA_TYPE) x);
#else
  sprintf (buf, BFP_FMT, x);
#endif

  /* Convert from the floating point string to a decimal* type.  */
  FROM_STRING (&s, buf, &context);
  IEEE_TO_HOST (s, &f);
  if (CONTEXT_TRAPS && (context.status & DEC_Inexact) != 0)
    DFP_RAISE (DEC_Inexact);
  return f;
}
コード例 #2
0
DFP_C_TYPE
BFP_TO_DFP (BFP_TYPE x)
{
  DFP_C_TYPE f;
  IEEE_TYPE s;
  char buf[BUFMAX];
  decContext context;

  decContextDefault (&context, CONTEXT_INIT);
  DFP_INIT_ROUNDMODE (context.round);

  /* Use a C library function to write the floating point value to a string.  */
  sprintf (buf, BFP_FMT, (BFP_VIA_TYPE) x);

  /* Convert from the floating point string to a decimal* type.  */
  FROM_STRING (&s, buf, &context);
  IEEE_TO_HOST (s, &f);

  if (DFP_EXCEPTIONS_ENABLED && context.status != 0)
    {
      /* decNumber exception flags we care about here.  */
      int ieee_flags;
      int dec_flags = DEC_IEEE_854_Inexact | DEC_IEEE_854_Invalid_operation
		      | DEC_IEEE_854_Overflow | DEC_IEEE_854_Underflow;
      dec_flags &= context.status;
      ieee_flags = DFP_IEEE_FLAGS (dec_flags);
      if (ieee_flags != 0)
        DFP_HANDLE_EXCEPTIONS (ieee_flags);
    }

  return f;
}
コード例 #3
0
ファイル: Utils.cpp プロジェクト: bcontant/TentGine
std_string GenerateTypeName(const char* in_typeName)
{
	std_string typeName;

	if (strncmp(in_typeName, ENUM_PREFIX, strlen(ENUM_PREFIX)) == 0)
		typeName = FROM_STRING(in_typeName + strlen(ENUM_PREFIX));

	else if (strncmp(in_typeName, STRUCT_PREFIX, strlen(STRUCT_PREFIX)) == 0)
		typeName = FROM_STRING(in_typeName + strlen(STRUCT_PREFIX));

	else if (strncmp(in_typeName, CLASS_PREFIX, strlen(CLASS_PREFIX)) == 0)
		typeName = FROM_STRING(in_typeName + strlen(CLASS_PREFIX));

	else
		typeName = FROM_STRING(in_typeName);

	CHECK_ERROR_MSG(ErrorCode::InvalidTypeName, typeName != L("") && typeName[0] != ' ', L("GenerateTypeName is returning a messed up type name."));

	return typeName;
}
コード例 #4
0
DFP_C_TYPE
INT_TO_DFP (INT_TYPE i)
{
  DFP_C_TYPE f;
  IEEE_TYPE s;
  char buf[BUFMAX];
  decContext context;

  decContextDefault (&context, CONTEXT_INIT);
  context.round = CONTEXT_ROUND;

  /* Use a C library function to get a floating point string.  */
  sprintf (buf, INT_FMT ".0", CAST_FOR_FMT(i));
  /* Convert from the floating point string to a decimal* type.  */
  FROM_STRING (&s, buf, &context);
  IEEE_TO_HOST (s, &f);
  if (CONTEXT_TRAPS && (context.status & DEC_Inexact) != 0)
    DFP_RAISE (DEC_Inexact);
  return f;
}
コード例 #5
0
/* decNumber doesn't provide support for conversions from 64-bit integer
   types, so do it the hard way.  */
DFP_C_TYPE
INT_TO_DFP (INT_TYPE i)
{
  DFP_C_TYPE f;
  IEEE_TYPE s;
  char buf[BUFMAX];
  decContext context;

  decContextDefault (&context, CONTEXT_INIT);
  DFP_INIT_ROUNDMODE (context.round);

  /* Use a C library function to get a floating point string.  */
  sprintf (buf, INT_FMT ".0", CAST_FOR_FMT(i));
  /* Convert from the floating point string to a decimal* type.  */
  FROM_STRING (&s, buf, &context);
  IEEE_TO_HOST (s, &f);

  if (DFP_EXCEPTIONS_ENABLED && context.status != 0)
    dfp_conversion_exceptions (context.status);

  return f;
}