Repository: airspeed-velocity/asv

Issue:
util.human_float doesn't print +-inf or nan properly
Raises exceptions in `math.log10`:
```
  File "asv/util.py", line 110, in human_float
    logv = math.log10(value)
ValueError: math domain error
```
on +/-inf or nan inputs.

This can be triggered in `asv show` and maybe elsewhere.

Discussion:

Patch:
diff --git a/asv/util.py b/asv/util.py
index c7a58e7..42688af 100644
--- a/asv/util.py
+++ b/asv/util.py
@@ -106,6 +106,13 @@ def human_float(value, significant=3, truncate_small=None, significant_zeros=Fal
     """
     if value == 0:
         return "0"
+    elif math.isinf(value) or math.isnan(value):
+        return "{}".format(value)
+    elif value < 0:
+        sign = "-"
+        value = -value
+    else:
+        sign = ""
 
     logv = math.log10(value)
     magnitude = int(math.floor(logv)) + 1
@@ -127,7 +134,7 @@ def human_float(value, significant=3, truncate_small=None, significant_zeros=Fal
     else:
         fmt = "{{0:.{0}f}}".format(num_digits)
 
-    formatted = fmt.format(value)
+    formatted = sign + fmt.format(value)
 
     if not significant_zeros and '.' in formatted and 'e' not in fmt:
         formatted = formatted.rstrip('0')


Test patch:
diff --git a/test/test_util.py b/test/test_util.py
index 364bcf2..ccd8832 100644
--- a/test/test_util.py
+++ b/test/test_util.py
@@ -192,6 +192,17 @@ def test_human_float():
         ("0", 0.001, 2, 0),
         ("0", 0.001, 2, 1),
         ("0.001", 0.001, 2, 2),
+
+        # non-finite
+        ("inf", float('inf'), 1),
+        ("-inf", -float('inf'), 1),
+        ("nan", float('nan'), 1),
+
+        # negative
+        ("-1", -1.2345, 1),
+        ("-0.00100", -0.001, 3, None, True),
+        ("-0", -0.001, 2, 1),
+        ("-0.001", -0.001, 2, 2),
     ]
 
     for item in items: