be careful how to write inf and nan (obs from Paulo Moura)
This commit is contained in:
parent
8a9f8aa1a6
commit
dd2232491a
29
C/write.c
29
C/write.c
@ -19,6 +19,7 @@ static char SccsId[] = "%W% %G%";
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
#include "Yap.h"
|
#include "Yap.h"
|
||||||
#include "Yatom.h"
|
#include "Yatom.h"
|
||||||
#include "YapHeap.h"
|
#include "YapHeap.h"
|
||||||
@ -128,10 +129,31 @@ wrputf(Float f, wrf writewch) /* writes a float */
|
|||||||
{
|
{
|
||||||
char s[256], *pt = s, ch;
|
char s[256], *pt = s, ch;
|
||||||
|
|
||||||
|
#if HAVE_ISNAN || defined(__WIN32)
|
||||||
|
if (isnan(f)) {
|
||||||
|
wrputs("(nan)", writewch);
|
||||||
|
lastw = separator;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (f < 0) {
|
if (f < 0) {
|
||||||
|
#if HAVE_ISINF || defined(_WIN32)
|
||||||
|
if (isinf(f)) {
|
||||||
|
wrputs("(-inf)", writewch);
|
||||||
|
lastw = separator;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (lastw == symbol)
|
if (lastw == symbol)
|
||||||
wrputc(' ', writewch);
|
wrputc(' ', writewch);
|
||||||
} else {
|
} else {
|
||||||
|
#if HAVE_ISINF || defined(_WIN32)
|
||||||
|
if (isinf(f)) {
|
||||||
|
wrputs("(+inf)", writewch);
|
||||||
|
lastw = separator;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (lastw == alphanum)
|
if (lastw == alphanum)
|
||||||
wrputc(' ', writewch);
|
wrputc(' ', writewch);
|
||||||
}
|
}
|
||||||
@ -140,14 +162,7 @@ wrputf(Float f, wrf writewch) /* writes a float */
|
|||||||
sprintf(s, RepAtom(AtomFloatFormat)->StrOfAE, f);
|
sprintf(s, RepAtom(AtomFloatFormat)->StrOfAE, f);
|
||||||
while (*pt == ' ')
|
while (*pt == ' ')
|
||||||
pt++;
|
pt++;
|
||||||
if (*pt == 'i' || *pt == 'n') /* inf or nan */ {
|
|
||||||
wrputc('(', writewch);
|
|
||||||
wrputc('+', writewch);
|
|
||||||
wrputs(pt, writewch);
|
wrputs(pt, writewch);
|
||||||
wrputc(')', writewch);
|
|
||||||
} else {
|
|
||||||
wrputs(pt, writewch);
|
|
||||||
}
|
|
||||||
if (*pt == '-') pt++;
|
if (*pt == '-') pt++;
|
||||||
while ((ch = *pt) != '\0') {
|
while ((ch = *pt) != '\0') {
|
||||||
if (ch < '0' || ch > '9')
|
if (ch < '0' || ch > '9')
|
||||||
|
Reference in New Issue
Block a user