Skip to content

Commit 124e098

Browse files
committed
parse nan, inf
1 parent 7ca05f9 commit 124e098

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pymbolic/parser.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ class Parser:
144144
r"[0-9]*\.[0-9]+[eEdD][+-]?[0-9]+([a-zA-Z]*)\b"),
145145
# has a letter tag
146146
pytools.lex.RE(r"[0-9]+([a-zA-Z]+)"),
147+
# inf, nan
148+
pytools.lex.RE("inf"), pytools.lex.RE("nan"),
147149
)),
148150
(_int, pytools.lex.RE(r"[0-9]+")),
149151

@@ -181,6 +183,14 @@ class Parser:
181183
}
182184

183185
def parse_float(self, s):
186+
if s == "inf":
187+
from math import inf
188+
return inf
189+
190+
if s == "nan":
191+
from math import nan
192+
return nan
193+
184194
return float(s.replace("d", "e").replace("D", "e"))
185195

186196
def parse_terminal(self, pstate):

0 commit comments

Comments
 (0)