Exemplo n.º 1
0
DEST_TYPE
PREFIXED_FUNCTION_NAME (SRC_TYPE a)
{
  DEST_TYPE f;
  char buf[BUFMAX];
  decContext context;
  IEEE_DEST_TYPE e;

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

  /* Use a C library function to get a floating point string.  */
  sprintf (buf, INT_FMT "", CAST_FOR_FMT(a));
  /* Convert from the floating point string to a decimal* type.  */
  /* PASTE(___decimal,PASTE(DEST,FromString))(&f, buf, &context);  */
  PASTE(decimal,PASTE(DEST,FromString))(&e, buf, &context);
  PASTE(PASTE(___ieee_,DEST),_to_host) (&e, (&f));

  if (context.status != 0) {
    int dec_flags = context.status & 
    (DEC_IEEE_854_Inexact|DEC_IEEE_854_Invalid_operation|DEC_IEEE_854_Overflow);
    DFP_HANDLE_EXCEPTIONS(DFP_IEEE_FLAGS(dec_flags));
  }

  return f;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
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;
}