parser should parse +inf,-inf,+nan,-nan as floating point numbers

write should write inf as +inf and nan as +nan


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@92 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2001-06-19 16:31:59 +00:00
parent 54e9dc271d
commit 7d50fd267d
2 changed files with 33 additions and 0 deletions

View File

@ -343,6 +343,14 @@ ParseList(void)
return (t);
}
#ifndef INFINITY
#define INFINITY (1.0/0.0)
#endif
#ifndef NAN
#define NAN (0.0/0.0)
#endif
static Term
ParseTerm(int prio)
{
@ -387,6 +395,29 @@ ParseTerm(int prio)
NextToken;
break;
}
} else if (tokptr->Tok == Name_tok) {
Atom at = (Atom)tokptr->TokInfo;
if ((Atom)t == AtomPlus) {
if (at == AtomInf) {
t = MkFloatTerm(INFINITY);
NextToken;
break;
} else if (at == AtomNan) {
t = MkFloatTerm(NAN);
NextToken;
break;
}
} else if ((Atom)t == AtomMinus) {
if (at == AtomInf) {
t = MkFloatTerm(-INFINITY);
NextToken;
break;
} else if (at == AtomNan) {
t = MkFloatTerm(NAN);
NextToken;
break;
}
}
}
if (opprio <= prio) {
/* try to parse as a prefix operator */

View File

@ -126,6 +126,8 @@ wrputf(Float f) /* writes a float */
sprintf(s, "%.6g", f);
while (*pt == ' ')
pt++;
if (*pt == 'i' || *pt == 'n') /* inf or nan */
wrputc('+');
wrputs(pt);
if (*pt == '-') pt++;
while ((ch = *pt) != '\0') {