From 231164f6eaf631f8a87af3831e2818115146d9ce Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sun, 30 Jan 2011 17:34:42 +0000 Subject: [PATCH] added: option 'group_digits' to Conv struct you can set how many digits should be grouped git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@338 e52654a7-88a9-db11-a3e9-0013d4bc506e --- CHANGELOG | 4 +++- COPYRIGHT | 2 +- ttmath/ttmathbig.h | 20 ++++++++++++++------ ttmath/ttmathtypes.h | 10 +++++++++- ttmath/ttmathuint.h | 3 ++- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 6b03f09..5f8fa2e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,9 +1,11 @@ -Version 0.9.3 prerelease (2010.09.29): +Version 0.9.3 prerelease (2011.01.30): * added: Parser::InitCGamma() initializing coefficients used when calculating the gamma (or factorial) function this speed up the next calculations you don't have to call this method explicitly these coefficients will be calculated when needed + * added: option 'group_digits' to Conv struct + you can set how many digits should be grouped Version 0.9.2 (2010.09.23): diff --git a/COPYRIGHT b/COPYRIGHT index f03126c..0eb8d17 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -1,4 +1,4 @@ -Copyright (c) 2006-2010, Tomasz Sowa +Copyright (c) 2006-2011, Tomasz Sowa All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/ttmath/ttmathbig.h b/ttmath/ttmathbig.h index dc6447e..dc3e98c 100644 --- a/ttmath/ttmathbig.h +++ b/ttmath/ttmathbig.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2010, Tomasz Sowa + * Copyright (c) 2006-2011, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -4738,15 +4738,19 @@ private: typename string_type::size_type & index) const { typedef typename string_type::size_type StrSize; - uint group = 0; - + + uint group = 0; StrSize i = index; + uint group_digits = conv.group_digits; + + if( group_digits < 1 ) + group_digits = 1; // adding group characters before the comma operator // i>0 because on the first position we don't put any additional grouping characters for( ; i>0 ; --i, ++group) { - if( group >= 3 ) + if( group >= group_digits ) { group = 0; new_man.insert(i, 1, static_cast(conv.group)); @@ -4763,11 +4767,15 @@ private: void ToString_Group_man_after_comma(string_type & new_man, const Conv & conv, typename string_type::size_type index) const { - uint group = 0; + uint group = 0; + uint group_digits = conv.group_digits; + + if( group_digits < 1 ) + group_digits = 1; for( ; index= 3 ) + if( group >= group_digits ) { group = 0; new_man.insert(index, 1, static_cast(conv.group)); diff --git a/ttmath/ttmathtypes.h b/ttmath/ttmathtypes.h index 8f1979b..539c100 100644 --- a/ttmath/ttmathtypes.h +++ b/ttmath/ttmathtypes.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2010, Tomasz Sowa + * Copyright (c) 2006-2011, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -465,6 +465,13 @@ namespace ttmath uint group; + /*! + how many digits should be grouped (it is used if 'group' is non zero) + default: 3 + */ + uint group_digits; + + /*! */ uint group_exp; // not implemented yet @@ -484,6 +491,7 @@ namespace ttmath comma = '.'; comma2 = ','; group = 0; + group_digits = 3; group_exp = 0; } }; diff --git a/ttmath/ttmathuint.h b/ttmath/ttmathuint.h index 8f26626..2c96a60 100644 --- a/ttmath/ttmathuint.h +++ b/ttmath/ttmathuint.h @@ -3225,7 +3225,8 @@ private: { temp.DivInt(b, &rem); character = static_cast( Misc::DigitToChar(rem) ); - result.insert(result.begin(), character); + result.insert(result.begin(), character); // !! it has O(n^2) complexity, change it + // take the one from winix } while( !temp.IsZero() );