Exemple #1
0
/**
 * rasqal_xsd_decimal_get_long:
 * @dec: XSD Decimal
 * @error_p: pointer to error flag
 * 
 * Get an XSD Decimal as a long (may lose precision)
 * 
 * Return value: long value or 0 on failure and *error_p is non-0
 **/
long
rasqal_xsd_decimal_get_long(rasqal_xsd_decimal* dec, int* error_p)
{
  long result = 0;

#if defined(RASQAL_DECIMAL_C99) || defined(RASQAL_DECIMAL_NONE)
  result=(long)dec->raw;
#endif
#ifdef RASQAL_DECIMAL_MPFR
  if(!mpfr_fits_slong_p(dec->raw, dec->rounding)) {
    if(error_p)
      *error_p = 1;
  } else
    result = mpfr_get_si(dec->raw, dec->rounding);
#endif
#ifdef RASQAL_DECIMAL_GMP
  if(!mpf_fits_slong_p(dec->raw)) {
    if(error_p)
      *error_p = 1;
  } else
    result = mpf_get_si(dec->raw);
#endif

  return result;
}
Exemple #2
0
/*
void camlidl_mpf_ml2c(value val, __mpf_struct* mpf)
{
  *mpf = *((mpf_ptr)(Data_custom_val(val)));
}
*/
int mpf_fits_int_p (mpf_t OP)
{
    if (mpf_fits_slong_p(OP)) {
        long v = mpf_get_si(OP);
        return (Min_long <= v && v <= Max_long);
    }
    else {
        return 0;
    }
}
Exemple #3
0
int sg_big_float_try_to_get_c_int_type(sg_big_float_t *src, enum sg_c_int_type *type)
{
    if (!src || !type)
        return -1;

    if (mpf_fits_sshort_p(src->mpf))
        *type = SGCINTTYPE_SSHORT;
    else if (mpf_fits_ushort_p(src->mpf))
        *type = SGCINTTYPE_USHORT;
    else if (mpf_fits_sint_p(src->mpf))
        *type = SGCINTTYPE_SINT;
    else if (mpf_fits_uint_p(src->mpf))
        *type = SGCINTTYPE_UINT;
    else if (mpf_fits_slong_p(src->mpf))
        *type = SGCINTTYPE_SLONG;
    else if (mpf_fits_ulong_p(src->mpf))
        *type = SGCINTTYPE_ULONG;

    return 0;
}