From cb34c8708ff9129643332b9bf54a215428c33194 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Mon, 1 Oct 2012 16:22:38 +0200
Subject: [PATCH] Fix preprocessor crash when an pre-computed constant equals
 NaN or Inf

---
 preprocessor/DataTree.hh | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/preprocessor/DataTree.hh b/preprocessor/DataTree.hh
index 17823d23f..3540a86de 100644
--- a/preprocessor/DataTree.hh
+++ b/preprocessor/DataTree.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2003-2011 Dynare Team
+ * Copyright (C) 2003-2012 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -27,6 +27,7 @@ using namespace std;
 #include <list>
 #include <sstream>
 #include <iomanip>
+#include <cmath>
 
 #include "SymbolTable.hh"
 #include "NumericalConstants.hh"
@@ -261,6 +262,13 @@ public:
 inline expr_t
 DataTree::AddPossiblyNegativeConstant(double v)
 {
+  /* Treat NaN and Inf separately. In particular, under Windows, converting
+     them to a string does not work as expected */
+  if (isnan(v))
+    return NaN;
+  if (isinf(v))
+    return (v < 0 ? MinusInfinity : Infinity);
+
   bool neg = false;
   if (v < 0)
     {
-- 
GitLab