diff options
author | xi <xi@18f92427-320e-0410-9341-c67f048884a3> | 2006-05-15 18:43:58 +0000 |
---|---|---|
committer | xi <xi@18f92427-320e-0410-9341-c67f048884a3> | 2006-05-15 18:43:58 +0000 |
commit | 9e4373cb22d580c500abeb1335fb5cce382a0fab (patch) | |
tree | 4cd6d2e6fa3e84b1441d0f7041274395cb6079ac | |
parent | d67ebba18c0b2ccd5b5077f91776a4691dbf51d9 (diff) | |
download | pyyaml-9e4373cb22d580c500abeb1335fb5cce382a0fab.tar.gz |
Dynamically determine the inf and nan values. Should fix #14.
Thanks to Scott Daniels for the report and the patch.
git-svn-id: http://svn.pyyaml.org/pyyaml/trunk@168 18f92427-320e-0410-9341-c67f048884a3
-rw-r--r-- | lib/yaml/constructor.py | 4 | ||||
-rw-r--r-- | lib/yaml/representer.py | 11 |
2 files changed, 11 insertions, 4 deletions
diff --git a/lib/yaml/constructor.py b/lib/yaml/constructor.py index 57ad53d..d83c7d3 100644 --- a/lib/yaml/constructor.py +++ b/lib/yaml/constructor.py @@ -231,7 +231,9 @@ class SafeConstructor(BaseConstructor): else: return sign*int(value) - inf_value = 1e300000 + inf_value = 1e300 + while repr(inf_value) != repr(inf_value*inf_value): + inf_value *= inf_value nan_value = inf_value/inf_value def construct_yaml_float(self, node): diff --git a/lib/yaml/representer.py b/lib/yaml/representer.py index cb37169..b78c882 100644 --- a/lib/yaml/representer.py +++ b/lib/yaml/representer.py @@ -192,9 +192,14 @@ class SafeRepresenter(BaseRepresenter): def represent_long(self, data): return self.represent_scalar(u'tag:yaml.org,2002:int', unicode(data)) - repr_pos_inf = repr(1e300000) - repr_neg_inf = repr(-1e300000) - repr_nan = repr(1e300000/1e300000) + inf_value = 1e300 + while repr(inf_value) != repr(inf_value*inf_value): + inf_value *= inf_value + nan_value = inf_value/inf_value + + repr_pos_inf = repr(inf_value) + repr_neg_inf = repr(-inf_value) + repr_nan = repr(inf_value/inf_value) def represent_float(self, data): repr_data = repr(data) |