You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ty...@apache.org on 2015/05/23 00:39:31 UTC

cassandra git commit: cqlsh: Improve default float precision behavior

Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 744db7014 -> 7f855d113


cqlsh: Improve default float precision behavior

Patch by Stefania Alborghetti; reviewed by Tyler Hobbs for
CASSANDRA-9224


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/7f855d11
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/7f855d11
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/7f855d11

Branch: refs/heads/cassandra-2.1
Commit: 7f855d113bef60808dd55735e70ec86646582de1
Parents: 744db70
Author: Stefania Alborghetti <st...@datastax.com>
Authored: Fri May 22 17:38:46 2015 -0500
Committer: Tyler Hobbs <ty...@gmail.com>
Committed: Fri May 22 17:38:46 2015 -0500

----------------------------------------------------------------------
 CHANGES.txt                  | 1 +
 pylib/cqlshlib/formatting.py | 8 ++++++++
 2 files changed, 9 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/7f855d11/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index ca12522..a4430c0 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.1.6
+ * (cqlsh) Better float precision by default (CASSANDRA-9224)
  * Improve estimated row count (CASSANDRA-9107)
  * Optimize range tombstone memory footprint (CASSANDRA-8603)
  * Use configured gcgs in anticompaction (CASSANDRA-9397)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/7f855d11/pylib/cqlshlib/formatting.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/formatting.py b/pylib/cqlshlib/formatting.py
index e9d22fd..2a99e23 100644
--- a/pylib/cqlshlib/formatting.py
+++ b/pylib/cqlshlib/formatting.py
@@ -14,6 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import sys
 import re
 import time
 import calendar
@@ -144,6 +145,13 @@ def format_floating_point_type(val, colormap, float_precision, **_):
     elif math.isinf(val):
         bval = 'Infinity'
     else:
+        exponent = int(math.log10(abs(val))) if abs(val) > sys.float_info.epsilon else -sys.maxint -1
+        if -4 <= exponent < float_precision:
+            # when this is true %g will not use scientific notation,
+            # increasing precision should not change this decision
+            # so we increase the precision to take into account the
+            # digits to the left of the decimal point
+            float_precision = float_precision + exponent + 1
         bval = '%.*g' % (float_precision, val)
     return colorme(bval, colormap, 'float')