Esempio n. 1
0
static Int p_get_depth_limit( USES_REGS1 )
{
  Int d = IntOfTerm(DEPTH);
  if (d % 2 == 1) 
    return(Yap_unify(ARG1, MkFloatTerm(INFINITY)));
  return(Yap_unify_constant(ARG1, MkIntTerm(d/2)));
}
Esempio n. 2
0
/// @memberof logsum/3
static Int
p_logsum( USES_REGS1 )
{                               /* X is Y        */
  Term t1 = Deref(ARG1);
  Term t2 = Deref(ARG2);
  int done = FALSE;
  Float f1, f2;
  
  while (!done) {
    if (IsFloatTerm(t1)) {
      f1 = FloatOfTerm(t1);
      done = TRUE;
    } else if (IsIntegerTerm(t1)) {
      f1 = IntegerOfTerm(t1);
      done = TRUE;
#if USE_GMP
    } else if (IsBigIntTerm(t1)) {
      f1 = Yap_gmp_to_float(t1);
      done = TRUE;
#endif
    } else {
      while (!(t1 = Eval(t1 PASS_REGS))) {
	if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) {
	  LOCAL_Error_TYPE = YAP_NO_ERROR;
	  if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, CP)) {
	    Yap_EvalError(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage);
	    return FALSE;
	  }
	} else {
	  Yap_EvalError(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
	  return FALSE;
	}
      }
    }
  }
  done = FALSE;
  while (!done) {
    if (IsFloatTerm(t2)) {
      f2 = FloatOfTerm(t2);
      done = TRUE;
    } else if (IsIntegerTerm(t2)) {
      f2 = IntegerOfTerm(t2);
      done = TRUE;
#if USE_GMP
    } else if (IsBigIntTerm(t2)) {
      f2 = Yap_gmp_to_float(t2);
      done = TRUE;
#endif
    } else {
      while (!(t2 = Eval(t2 PASS_REGS))) {
	if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) {
	  LOCAL_Error_TYPE = YAP_NO_ERROR;
	  if (!Yap_gcl(LOCAL_Error_Size, 2, ENV, CP)) {
	    Yap_EvalError(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage);
	    return FALSE;
	  }
	} else {
	  Yap_EvalError(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
	  return FALSE;
	}
      }
    }
  }
  if (f1 >= f2) {
    Float fi = exp(f2-f1);
    return Yap_unify(ARG3,MkFloatTerm(f1+log(1+fi)));
  } else {
    Float fi = exp(f1-f2);
    return Yap_unify(ARG3,MkFloatTerm(f2+log(1+fi)));
  }
}