Esempio n. 1
0
char
_floatnum2logic(
  t_longint* longint,
  cfloatnum x)
{
  floatstruct tmp;
  int digits;

  digits = float_getexponent(x)+1;
  if (float_iszero(x) || digits <= 0)
  {
    longint->length = 1;
    longint->value[0] = 0;
  }
  else
  {
    if (digits > MATHPRECISION)
      return 0;

    float_create(&tmp);
    /* floatnum2longint rounds, we have to truncate first */
    float_copy(&tmp, x, digits);
    if (float_getsign(x) < 0)
      float_add(&tmp, &tmp, &c1, EXACT);
    _floatnum2longint(longint, &tmp);
    float_free(&tmp);
    if (_bitlength(longint) > LOGICRANGE)
      return 0;
  }
  _zeroextend(longint);
  if (float_getsign(x) < 0)
    _not(longint);
  return 1;
}
Esempio n. 2
0
static Error
_fixp2longint(
  p_number_desc n,
  t_longint* l,
  floatnum x,
  int scale)
{
  Error result;
  _scale2int(x, scale, n->prefix.base);
  result = _floatnum2longint(l, x);
  if (result != Success)
    return result;
  _setlongintdesc(&n->fracpart, l, n->prefix.base);
  return Success;
}