gilch: I would also prefer one canonical capitalization, but I'm more inclined to use all-lowercase `nan` and `inf`, since that is the Python repr.
```
>>> float('NaN')
nan
>>> float('Inf')
inf
```
Kodiologist: I noticed that, but I figured that starting with a capital letter is better for symmetry with `False`, `True`, and `None`, and the meaning of `NaN` is clearer when written in CamelCase.

Also, I'm not 100% sure that the Python `repr` is platform-independent.
tuturto: For what it's worth, I get all lowercase inf and nan when doing ```float('NaN')``` on my Windows 10 machine or Linux machine, on both Python 2.x and 3.x. That said, I kind of like ```NaN``` nicer looking than ```nan```.

I would be inclined to choose ```NaN``` and ```Inf```` over ```nan``` and ```inf````, but I don't feel about this particularly strongly.
gilch: I'm not sure what to think. I guess my feelings are not that strong either. @kirbyfan64, what say you?
kirbyfan64: My only question is whether or not it's actually *worthwhile* to add so much extra code just to check the inf and NaN capitalization...
Kodiologist: I'm all for concise implementation, but surely you don't mean to suggest that we should interpret all of `Nan`, `nan`, `nAN`, etc. as the special floating-point value, in defiance of the case-sensitivity of the rest of the language, do you? Surely a bunch of code is a reasonable price to pay for avoiding that.
Kodiologist: C'mon, guys, nothing will happen if you don't make any decisions.
kirbyfan64: @Kodiologist can you rebase this?
diff --git a/NEWS b/NEWS
index a21c5142..4c963f4f 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ Changes from 0.13.0
    * The compiler now automatically promotes values to Hy model objects
      as necessary, so you can write ``(eval `(+ 1 ~n))`` instead of
      ``(eval `(+ 1 ~(HyInteger n)))``
+   * Literal `Inf`s and `NaN`s must now be capitalized like that
 
    [ Bug Fixes ]
    * Numeric literals are no longer parsed as symbols when followed by a dot
diff --git a/docs/language/api.rst b/docs/language/api.rst
index 5ed646d0..5241b3ab 100644
--- a/docs/language/api.rst
+++ b/docs/language/api.rst
@@ -52,6 +52,9 @@ digits.
 
     (print 10,000,000,000 10_000_000_000)
 
+Unlike Python, Hy provides literal forms for NaN and infinity: `NaN`, `Inf`,
+and `-Inf`.
+
 string literals
 ---------------
 
diff --git a/hy/contrib/hy_repr.hy b/hy/contrib/hy_repr.hy
index b5289740..20535044 100644
--- a/hy/contrib/hy_repr.hy
+++ b/hy/contrib/hy_repr.hy
@@ -2,8 +2,10 @@
 ;; This file is part of Hy, which is free software licensed under the Expat
 ;; license. See the LICENSE.
 
-(import [hy._compat [PY3 str-type bytes-type long-type]])
-(import [hy.models [HyObject HyExpression HySymbol HyKeyword HyInteger HyList HyDict HySet HyString HyBytes]])
+(import
+  [math [isnan]]
+  [hy._compat [PY3 str-type bytes-type long-type]]
+  [hy.models [HyObject HyExpression HySymbol HyKeyword HyInteger HyFloat HyComplex HyList HyDict HySet HyString HyBytes]])
 
 (defn hy-repr [obj]
   (setv seen (set))
@@ -72,8 +74,14 @@
         (.format "(int {})" (repr x))
       (and (not PY3) (in t [long_type HyInteger]))
         (.rstrip (repr x) "L")
-      (is t complex)
-        (.strip (repr x) "()")
+      (and (in t [float HyFloat]) (isnan x))
+        "NaN"
+      (= x Inf)
+        "Inf"
+      (= x -Inf)
+        "-Inf"
+      (in t [complex HyComplex])
+        (.replace (.replace (.strip (repr x) "()") "inf" "Inf") "nan" "NaN")
       (is t fraction)
         (.format "{}/{}" (f x.numerator q) (f x.denominator q))
       ; else
diff --git a/hy/models.py b/hy/models.py
index 93cce18a..77c580fb 100644
--- a/hy/models.py
+++ b/hy/models.py
@@ -3,6 +3,7 @@
 # license. See the LICENSE.
 
 from __future__ import unicode_literals
+from math import isnan, isinf
 from hy._compat import PY3, str_type, bytes_type, long_type, string_types
 from fractions import Fraction
 
@@ -142,15 +143,24 @@ if not PY3:  # do not add long on python3
     _wrappers[long_type] = HyInteger
 
 
+def check_inf_nan_cap(arg, value):
+    if isinstance(arg, string_types):
+        if isinf(value) and "Inf" not in arg:
+            raise ValueError('Inf must be capitalized as "Inf"')
+        if isnan(value) and "NaN" not in arg:
+            raise ValueError('NaN must be capitalized as "NaN"')
+
+
 class HyFloat(HyObject, float):
     """
     Internal representation of a Hy Float. May raise a ValueError as if
     float(foo) was called, given HyFloat(foo).
     """
 
-    def __new__(cls, number, *args, **kwargs):
-        number = float(strip_digit_separators(number))
-        return super(HyFloat, cls).__new__(cls, number)
+    def __new__(cls, num, *args, **kwargs):
+        value = super(HyFloat, cls).__new__(cls, strip_digit_separators(num))
+        check_inf_nan_cap(num, value)
+        return value
 
 _wrappers[float] = HyFloat
 
@@ -161,9 +171,18 @@ class HyComplex(HyObject, complex):
     complex(foo) was called, given HyComplex(foo).
     """
 
-    def __new__(cls, number, *args, **kwargs):
-        number = complex(strip_digit_separators(number))
-        return super(HyComplex, cls).__new__(cls, number)
+    def __new__(cls, num, *args, **kwargs):
+        value = super(HyComplex, cls).__new__(cls, strip_digit_separators(num))
+        if isinstance(num, string_types):
+            p1, _, p2 = num.lstrip("+-").replace("-", "+").partition("+")
+            if p2:
+                check_inf_nan_cap(p1, value.real)
+                check_inf_nan_cap(p2, value.imag)
+            elif "j" in p1:
+                check_inf_nan_cap(p1, value.imag)
+            else:
+                check_inf_nan_cap(p1, value.real)
+        return value
 
 _wrappers[complex] = HyComplex
 

Any capitalization of "nan" or "inf" is interpreted as a float, not a symbol
For example:

    => (setv Nan 5)
      File "<input>", line 1, column 7

      (setv Nan 5)
            ^--^
    HyTypeError: b"Can't assign or delete a HyFloat"

The fact that Hy accepts literals for floating-point infinity and NaN, albeit unintentional, is a nice feature that we might as well keep. But, Hy ought to recognize only one capitalization.
diff --git a/tests/native_tests/contrib/hy_repr.hy b/tests/native_tests/contrib/hy_repr.hy
index 0a678b41..9bbdd095 100644
--- a/tests/native_tests/contrib/hy_repr.hy
+++ b/tests/native_tests/contrib/hy_repr.hy
@@ -3,16 +3,17 @@
 ;; license. See the LICENSE.
 
 (import
+  [math [isnan]]
   [hy.contrib.hy-repr [hy-repr]])
 
 (defn test-hy-repr-roundtrip-from-value []
   ; Test that a variety of values round-trip properly.
   (setv values [
     None False True
-    5 5.1 '5 '5.1
+    5 5.1 '5 '5.1 Inf -Inf
     (int 5)
     1/2
-    5j 5.1j 2+1j 1.2+3.4j
+    5j 5.1j 2+1j 1.2+3.4j Inf-Infj
     "" b""
     '"" 'b""
     "apple bloom" b"apple bloom" "⚘"
@@ -32,10 +33,17 @@
   (for [original-val values]
     (setv evaled (eval (read-str (hy-repr original-val))))
     (assert (= evaled original-val))
-    (assert (is (type evaled) (type original-val)))))
+    (assert (is (type evaled) (type original-val))))
+  (assert (isnan (eval (read-str (hy-repr NaN))))))
 
 (defn test-hy-repr-roundtrip-from-str []
   (setv strs [
+    "'Inf"
+    "'-Inf"
+    "'NaN"
+    "1+2j"
+    "NaN+NaNj"
+    "'NaN+NaNj"
     "[1 2 3]"
     "'[1 2 3]"
     "[1 'a 3]"
diff --git a/tests/test_lex.py b/tests/test_lex.py
index e5f43223..dfac923c 100644
--- a/tests/test_lex.py
+++ b/tests/test_lex.py
@@ -2,6 +2,7 @@
 # This file is part of Hy, which is free software licensed under the Expat
 # license. See the LICENSE.
 
+from math import isnan
 from hy.models import (HyExpression, HyInteger, HyFloat, HyComplex, HySymbol,
                        HyString, HyDict, HyList, HySet, HyCons)
 from hy.lex import LexException, PrematureEndOfInput, tokenize
@@ -91,16 +92,38 @@ def test_lex_expression_float():
     assert objs == [HyExpression([HySymbol("foo"), HyFloat(1.e7)])]
 
 
+def test_lex_nan_and_inf():
+
+    assert isnan(tokenize("NaN")[0])
+    assert tokenize("Nan") == [HySymbol("Nan")]
+    assert tokenize("nan") == [HySymbol("nan")]
+    assert tokenize("NAN") == [HySymbol("NAN")]
+
+    assert tokenize("Inf") == [HyFloat(float("inf"))]
+    assert tokenize("inf") == [HySymbol("inf")]
+    assert tokenize("INF") == [HySymbol("INF")]
+
+    assert tokenize("-Inf") == [HyFloat(float("-inf"))]
+    assert tokenize("-inf") == [HySymbol("_inf")]
+    assert tokenize("-INF") == [HySymbol("_INF")]
+
+
 def test_lex_expression_complex():
     """ Make sure expressions can produce complex """
-    objs = tokenize("(foo 2.j)")
-    assert objs == [HyExpression([HySymbol("foo"), HyComplex(2.j)])]
-    objs = tokenize("(foo -0.5j)")
-    assert objs == [HyExpression([HySymbol("foo"), HyComplex(-0.5j)])]
-    objs = tokenize("(foo 1.e7j)")
-    assert objs == [HyExpression([HySymbol("foo"), HyComplex(1.e7j)])]
-    objs = tokenize("(foo j)")
-    assert objs == [HyExpression([HySymbol("foo"), HySymbol("j")])]
+
+    def t(x): return tokenize("(foo {})".format(x))
+
+    def f(x): return [HyExpression([HySymbol("foo"), x])]
+
+    assert t("2.j") == f(HyComplex(2.j))
+    assert t("-0.5j") == f(HyComplex(-0.5j))
+    assert t("1.e7j") == f(HyComplex(1e7j))
+    assert t("j") == f(HySymbol("j"))
+    assert isnan(t("NaNj")[0][1].imag)
+    assert t("nanj") == f(HySymbol("nanj"))
+    assert t("Inf+Infj") == f(HyComplex(complex(float("inf"), float("inf"))))
+    assert t("Inf-Infj") == f(HyComplex(complex(float("inf"), float("-inf"))))
+    assert t("Inf-INFj") == f(HySymbol("Inf_INFj"))
 
 
 def test_lex_digit_separators():

pip install -e .
parse_log_pytest
pytest
pytest tox Pygments>=1.6 Sphinx sphinx_rtd_theme
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster==0.7.13
appdirs==1.4.4
args==0.1.0
astor==0.8.1
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
Babel==2.11.0
certifi==2021.5.30
charset-normalizer==2.0.12
clint==0.5.1
distlib==0.3.9
docutils==0.18.1
filelock==3.4.1
-e git+https://github.com/hylang/hy.git@7c53a07b93084a0970cdf192d4aa2d712d557154#egg=hy
idna==3.10
imagesize==1.4.1
importlib-metadata==4.8.3
importlib-resources==5.4.0
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
Jinja2==3.0.3
MarkupSafe==2.0.1
more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
platformdirs==2.4.0
pluggy @ file:///tmp/build/80754af9/pluggy_1615976315926/work
py @ file:///opt/conda/conda-bld/py_1644396412707/work
Pygments==2.14.0
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
pytest==6.2.4
pytz==2025.2
requests==2.27.1
rply==0.7.8
six==1.17.0
snowballstemmer==2.2.0
Sphinx==5.3.0
sphinx-rtd-theme==2.0.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jquery==4.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
tox==3.28.0
typing_extensions @ file:///opt/conda/conda-bld/typing_extensions_1647553014482/work
urllib3==1.26.20
virtualenv==20.17.1
zipp @ file:///tmp/build/80754af9/zipp_1633618647012/work

name: hy
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=21.4.0=pyhd3eb1b0_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - more-itertools=8.12.0=pyhd3eb1b0_0
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=21.3=pyhd3eb1b0_0
  - pip=21.2.2=py36h06a4308_0
  - pluggy=0.13.1=py36h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pytest=6.2.4=py36h06a4308_2
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.13
      - appdirs==1.4.4
      - args==0.1.0
      - astor==0.8.1
      - babel==2.11.0
      - charset-normalizer==2.0.12
      - clint==0.5.1
      - distlib==0.3.9
      - docutils==0.18.1
      - filelock==3.4.1
      - idna==3.10
      - imagesize==1.4.1
      - importlib-metadata==4.8.3
      - importlib-resources==5.4.0
      - jinja2==3.0.3
      - markupsafe==2.0.1
      - platformdirs==2.4.0
      - pygments==2.14.0
      - pytz==2025.2
      - requests==2.27.1
      - rply==0.7.8
      - six==1.17.0
      - snowballstemmer==2.2.0
      - sphinx==5.3.0
      - sphinx-rtd-theme==2.0.0
      - sphinxcontrib-applehelp==1.0.2
      - sphinxcontrib-devhelp==1.0.2
      - sphinxcontrib-htmlhelp==2.0.0
      - sphinxcontrib-jquery==4.1
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==1.0.3
      - sphinxcontrib-serializinghtml==1.1.5
      - tox==3.28.0
      - urllib3==1.26.20
      - virtualenv==20.17.1
prefix: /opt/conda/envs/hy

tests/native_tests/contrib/hy_repr.hy::test_hy_repr_roundtrip_from_str tests/test_lex.py::test_lex_nan_and_inf tests/test_lex.py::test_lex_expression_complex
tests/native_tests/contrib/hy_repr.hy::test_hy_repr_roundtrip_from_value tests/native_tests/contrib/hy_repr.hy::test_hy_model_constructors tests/native_tests/contrib/hy_repr.hy::test_hy_repr_self_reference tests/native_tests/contrib/hy_repr.hy::test_hy_repr_dunder_method tests/native_tests/contrib/hy_repr.hy::test_hy_repr_fallback tests/test_lex.py::test_lex_exception tests/test_lex.py::test_unbalanced_exception tests/test_lex.py::test_lex_single_quote_err tests/test_lex.py::test_lex_expression_symbols tests/test_lex.py::test_lex_expression_strings tests/test_lex.py::test_lex_expression_integer tests/test_lex.py::test_lex_symbols tests/test_lex.py::test_lex_strings tests/test_lex.py::test_lex_integers tests/test_lex.py::test_lex_fractions tests/test_lex.py::test_lex_expression_float tests/test_lex.py::test_lex_digit_separators tests/test_lex.py::test_lex_bad_attrs tests/test_lex.py::test_lex_line_counting tests/test_lex.py::test_lex_line_counting_multi tests/test_lex.py::test_lex_line_counting_multi_inner tests/test_lex.py::test_dicts tests/test_lex.py::test_sets tests/test_lex.py::test_nospace tests/test_lex.py::test_escapes tests/test_lex.py::test_unicode_escapes tests/test_lex.py::test_hashbang tests/test_lex.py::test_complex tests/test_lex.py::test_tag_macro tests/test_lex.py::test_lex_comment_382 tests/test_lex.py::test_lex_mangling_star tests/test_lex.py::test_lex_mangling_hyphen tests/test_lex.py::test_lex_mangling_qmark tests/test_lex.py::test_lex_mangling_bang tests/test_lex.py::test_unmangle tests/test_lex.py::test_simple_cons tests/test_lex.py::test_dotted_list tests/test_lex.py::test_cons_list
NEWS hy/models.py hy/contrib/hy_repr.hy docs/language/api.rst
NEWS hy/models.py hy/contrib/hy_repr.hy docs/language/api.rst