add isinf and isnan.

This commit is contained in:
Vitor Santos Costa 2013-07-16 09:58:57 -05:00
parent 459ab89d7d
commit 55a440cf0c
2 changed files with 72 additions and 0 deletions

View File

@ -198,6 +198,62 @@ p_is( USES_REGS1 )
return Yap_unify_constant(ARG1,out);
}
static Int
p_isnan( USES_REGS1 )
{ /* X is Y */
Term out = 0L;
while (!(out = Eval(Deref(ARG1) 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_Error(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
return FALSE;
}
}
if (IsVarTerm(out)) {
Yap_Error(INSTANTIATION_ERROR, out, "isnan/1");
return FALSE;
}
if (!IsFloatTerm(out)) {
Yap_Error(TYPE_ERROR_FLOAT, out, "isnan/1");
return FALSE;
}
return isnan(FloatOfTerm(out));
}
static Int
p_isinf( USES_REGS1 )
{ /* X is Y */
Term out = 0L;
while (!(out = Eval(Deref(ARG1) 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_Error(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage);
return FALSE;
}
} else {
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
return FALSE;
}
}
if (IsVarTerm(out)) {
Yap_Error(INSTANTIATION_ERROR, out, "isinf/1");
return FALSE;
}
if (!IsFloatTerm(out)) {
Yap_Error(TYPE_ERROR_FLOAT, out, "isinf/1");
return FALSE;
}
return isinf(FloatOfTerm(out));
}
Int
Yap_ArithError(yap_error_number type, Term where, char *format,...)
{
@ -360,6 +416,8 @@ Yap_InitEval(void)
Yap_InitUnaryExps();
Yap_InitBinaryExps();
Yap_InitCPred("is", 2, p_is, 0L);
Yap_InitCPred("isnan", 1, p_isnan, TestPredFlag);
Yap_InitCPred("isinf", 1, p_isinf, TestPredFlag);
Yap_InitCPredBack("between", 3, 2, init_between, cont_between, 0);
}

View File

@ -4458,6 +4458,20 @@ The following predicates provide counting:
@cnindex plus/3
True if @var{Int3} = @var{Int1} + @var{Int2}. At least two of the
three arguments must be instantiated to integers.
@item isnan(+@var{Float})
@findex isnan/1
@snindex isnan/1
@cnindex isnan/1
True if @var{Float} is not a number.
@item isinf(+@var{Float})
@findex isinf/1
@snindex isinf/1
@cnindex isinf/1
True if floating point expression @var{Float} evaluates to infinity.
@end table
@node I/O, Database, Arithmetic, Top