From 8f419c5eab0876fcf958529d08f5de42920568a4 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 26 Jul 2014 18:03:51 +0900 Subject: [PATCH] write +inf.0, -inf.0, +nan.0, ... --- src/write.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/write.c b/src/write.c index 61551b1a..46b82470 100644 --- a/src/write.c +++ b/src/write.c @@ -2,6 +2,8 @@ * See Copyright Notice in picrin.h */ +#include + #include "picrin.h" #include "picrin/port.h" #include "picrin/pair.h" @@ -185,6 +187,7 @@ write_core(struct writer_control *p, pic_value obj) size_t i; xh_entry *e; int c; + float f; /* shared objects */ if (pic_vtype(obj) == PIC_VTYPE_HEAP @@ -257,7 +260,14 @@ write_core(struct writer_control *p, pic_value obj) } break; case PIC_TT_FLOAT: - xfprintf(file, "%f", pic_float(obj)); + f = pic_float(obj); + if (isnan(f)) { + xfprintf(file, signbit(f) ? "-nan.0" : "+nan.0"); + } else if (isinf(f)) { + xfprintf(file, signbit(f) ? "-inf.0" : "+inf.0"); + } else { + xfprintf(file, "%f", pic_float(obj)); + } break; case PIC_TT_INT: xfprintf(file, "%d", pic_int(obj));