fix number_ operations to handle number_*(2,[L]).

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@189 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2001-11-19 23:19:23 +00:00
parent 338cd94473
commit 10394c4c99
2 changed files with 93 additions and 99 deletions

View File

@ -821,65 +821,63 @@ static Int
p_number_chars(void) p_number_chars(void)
{ {
char *String = (char *)TR; /* alloc temp space on Trail */ char *String = (char *)TR; /* alloc temp space on Trail */
register Term t = Deref(ARG2); register Term t = Deref(ARG2), t1 = Deref(ARG1);
Term NewT; Term NewT;
register char *s = String; register char *s = String;
if (IsVarTerm(t)) { if (IsNonVarTerm(t1)) {
Term t1 = Deref(ARG1); Term NewT;
if (IsVarTerm(t1)) { if (!IsNumTerm(t1)) {
Error(INSTANTIATION_ERROR, t1, "number_chars/2"); Error(TYPE_ERROR_NUMBER, t1, "number_chars/2");
return(FALSE); return(FALSE);
} else { } else if (IsIntTerm(t1)) {
Term NewT;
if (!IsNumTerm(t1)) {
Error(TYPE_ERROR_NUMBER, t1, "number_chars/2");
return(FALSE);
} else if (IsIntTerm(t1)) {
#if SHORT_INTS #if SHORT_INTS
sprintf(String, "%ld", IntOfTerm(t1)); sprintf(String, "%ld", IntOfTerm(t1));
#else #else
sprintf(String, "%d", IntOfTerm(t1)); sprintf(String, "%d", IntOfTerm(t1));
#endif
if (yap_flags[YAP_TO_CHARS_FLAG] == QUINTUS_TO_CHARS) {
NewT = StringToList(String);
} else {
NewT = StringToListOfAtoms(String);
}
return (unify(NewT, ARG2));
} else if (IsFloatTerm(t1)) {
sprintf(String, "%f", FloatOfTerm(t1));
if (yap_flags[YAP_TO_CHARS_FLAG] == QUINTUS_TO_CHARS) {
NewT = StringToList(String);
} else {
NewT = StringToListOfAtoms(String);
}
return (unify(NewT, ARG2));
} else if (IsLongIntTerm(t1)) {
#if SHORT_INTS
sprintf(String, "%ld", LongIntOfTerm(t1));
#else
sprintf(String, "%d", LongIntOfTerm(t1));
#endif
if (yap_flags[YAP_TO_CHARS_FLAG] == QUINTUS_TO_CHARS) {
NewT = StringToList(String);
} else {
NewT = StringToListOfAtoms(String);
}
return (unify(NewT, ARG2));
#if USE_GMP
} else if (IsBigIntTerm(t1)) {
mpz_get_str(String, 10, BigIntOfTerm(t1));
if (yap_flags[YAP_TO_CHARS_FLAG] == QUINTUS_TO_CHARS) {
NewT = StringToList(String);
} else {
NewT = StringToListOfAtoms(String);
}
return (unify(NewT, ARG2));
#endif #endif
if (yap_flags[YAP_TO_CHARS_FLAG] == QUINTUS_TO_CHARS) {
NewT = StringToList(String);
} else {
NewT = StringToListOfAtoms(String);
} }
return (unify(NewT, ARG2));
} else if (IsFloatTerm(t1)) {
sprintf(String, "%f", FloatOfTerm(t1));
if (yap_flags[YAP_TO_CHARS_FLAG] == QUINTUS_TO_CHARS) {
NewT = StringToList(String);
} else {
NewT = StringToListOfAtoms(String);
}
return (unify(NewT, ARG2));
} else if (IsLongIntTerm(t1)) {
#if SHORT_INTS
sprintf(String, "%ld", LongIntOfTerm(t1));
#else
sprintf(String, "%d", LongIntOfTerm(t1));
#endif
if (yap_flags[YAP_TO_CHARS_FLAG] == QUINTUS_TO_CHARS) {
NewT = StringToList(String);
} else {
NewT = StringToListOfAtoms(String);
}
return (unify(NewT, ARG2));
#if USE_GMP
} else if (IsBigIntTerm(t1)) {
mpz_get_str(String, 10, BigIntOfTerm(t1));
if (yap_flags[YAP_TO_CHARS_FLAG] == QUINTUS_TO_CHARS) {
NewT = StringToList(String);
} else {
NewT = StringToListOfAtoms(String);
}
return (unify(NewT, ARG2));
#endif
} }
} }
if (IsVarTerm(t)) {
Error(INSTANTIATION_ERROR, t1, "number_chars/2");
return(FALSE);
}
if (t == TermNil) { if (t == TermNil) {
return (FALSE); return (FALSE);
} }
@ -956,50 +954,50 @@ static Int
p_number_atom(void) p_number_atom(void)
{ {
char *String = (char *)TR; /* alloc temp space on Trail */ char *String = (char *)TR; /* alloc temp space on Trail */
register Term t = Deref(ARG2); register Term t = Deref(ARG2), t1 = Deref(ARG1);
Term NewT; Term NewT;
register char *s = String; register char *s = String;
if (IsVarTerm(t)) { if (IsNonVarTerm(t1)) {
Term t1 = Deref(ARG1); if (IsIntTerm(t1)) {
if (IsVarTerm(t1)) {
Error(INSTANTIATION_ERROR, t1, "number_chars/2");
return(FALSE);
} else {
Term NewT; Term NewT;
if (IsIntTerm(t1)) {
#if SHORT_INTS #if SHORT_INTS
sprintf(String, "%ld", IntOfTerm(t1)); sprintf(String, "%ld", IntOfTerm(t1));
#else #else
sprintf(String, "%d", IntOfTerm(t1)); sprintf(String, "%d", IntOfTerm(t1));
#endif #endif
NewT = MkAtomTerm(LookupAtom(String)); NewT = MkAtomTerm(LookupAtom(String));
return (unify(NewT, ARG2)); return (unify(NewT, ARG2));
} else if (IsFloatTerm(t1)) { } else if (IsFloatTerm(t1)) {
sprintf(String, "%f", FloatOfTerm(t1)); Term NewT;
NewT = MkAtomTerm(LookupAtom(String)); sprintf(String, "%f", FloatOfTerm(t1));
return (unify(NewT, ARG2)); NewT = MkAtomTerm(LookupAtom(String));
} else if (IsLongIntTerm(t1)) { return (unify(NewT, ARG2));
} else if (IsLongIntTerm(t1)) {
Term NewT;
#if SHORT_INTS #if SHORT_INTS
sprintf(String, "%ld", LongIntOfTerm(t1)); sprintf(String, "%ld", LongIntOfTerm(t1));
#else #else
sprintf(String, "%d", LongIntOfTerm(t1)); sprintf(String, "%d", LongIntOfTerm(t1));
#endif #endif
NewT = MkAtomTerm(LookupAtom(String)); NewT = MkAtomTerm(LookupAtom(String));
return (unify(NewT, ARG2)); return (unify(NewT, ARG2));
#if USE_GMP #if USE_GMP
} else if (IsBigIntTerm(t1)) { } else if (IsBigIntTerm(t1)) {
mpz_get_str(String, 10, BigIntOfTerm(t1)); Term NewT;
NewT = MkAtomTerm(LookupAtom(String)); mpz_get_str(String, 10, BigIntOfTerm(t1));
return (unify(NewT, ARG2)); NewT = MkAtomTerm(LookupAtom(String));
return (unify(NewT, ARG2));
#endif #endif
} else { } else {
Error(TYPE_ERROR_NUMBER, t1, "number_atom/2"); Error(TYPE_ERROR_NUMBER, t1, "number_atom/2");
return(FALSE); return(FALSE);
}
} }
} }
if (IsVarTerm(t)) {
Error(INSTANTIATION_ERROR, t, "number_chars/2");
return(FALSE);
}
if (t == TermNil) { if (t == TermNil) {
return (FALSE); return (FALSE);
} }
@ -1019,22 +1017,12 @@ static Int
p_number_codes(void) p_number_codes(void)
{ {
char *String = (char *)TR; /* alloc temp space on Trail */ char *String = (char *)TR; /* alloc temp space on Trail */
register Term t = Deref(ARG2); register Term t = Deref(ARG2), t1 = Deref(ARG1);
Term NewT; Term NewT;
register char *s = String; register char *s = String;
if (IsVarTerm(t)) { if (IsNonVarTerm(t1)) {
Term t1; if (IsIntTerm(t1)) {
Term NewT;
if (IsVarTerm(t1 = Deref(ARG1))) {
Error(INSTANTIATION_ERROR, t1, "number_codes/2");
return(FALSE);
}
if (!IsNumTerm(t1)) {
Error(TYPE_ERROR_NUMBER, t1, "number_codes/2");
return(FALSE);
} else if (IsIntTerm(t1)) {
#if SHORT_INTS #if SHORT_INTS
sprintf(String, "%ld", IntOfTerm(t1)); sprintf(String, "%ld", IntOfTerm(t1));
#else #else
@ -1055,13 +1043,19 @@ p_number_codes(void)
NewT = StringToList(String); NewT = StringToList(String);
return (unify(NewT, ARG2)); return (unify(NewT, ARG2));
#if USE_GMP #if USE_GMP
} else if (IsBigIntTerm(t1)) { } else if (IsBigIntTerm(t1)) {
mpz_get_str(String, 10, BigIntOfTerm(t1)); mpz_get_str(String, 10, BigIntOfTerm(t1));
NewT = StringToList(String); NewT = StringToList(String);
return (unify(NewT, ARG2)); return (unify(NewT, ARG2));
#endif #endif
} else {
Error(TYPE_ERROR_NUMBER, t1, "number_codes/2");
return(FALSE);
} }
} }
if (IsVarTerm(t)) {
Error(INSTANTIATION_ERROR, t, "number_codes/2");
}
if (t == TermNil) { if (t == TermNil) {
return (FALSE); return (FALSE);
} }

View File

@ -6683,7 +6683,7 @@ As @code{member/2}, but may only be used to test whether a known
@var{Element} occurs in a known Set. In return for this limited use, it @var{Element} occurs in a known Set. In return for this limited use, it
is more efficient when it is applicable. is more efficient when it is applicable.
@item nth0(?@var{N}, +@var{List}, ?@var{Elem}) @item nth0(?@var{N}, ?@var{List}, ?@var{Elem})
@findex nth0/2 @findex nth0/2
@syindex nth0/2 @syindex nth0/2
@cnindex nth0/2 @cnindex nth0/2
@ -6693,7 +6693,7 @@ N elements and unify @var{Elem} with the next.) It can only be used to
select a particular element given the list and index. For that select a particular element given the list and index. For that
task it is more efficient than @code{member/2} task it is more efficient than @code{member/2}
@item nth(?@var{N}, +@var{List}, ?@var{Elem}) @item nth(?@var{N}, ?@var{List}, ?@var{Elem})
@findex nth/2 @findex nth/2
@syindex nth/2 @syindex nth/2
@cnindex nth/2 @cnindex nth/2