8 Commits
0.9.2 ... 0.9.3

Author SHA1 Message Date
506840787a added: some pragmas for the clang compiler:
#pragma clang diagnostic ignored "-Wtautological-compare"
         to get rid off some warning messages
changed: changing version number to 0.9.3 release



git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@436 e52654a7-88a9-db11-a3e9-0013d4bc506e
2012-11-28 16:19:05 +00:00
e58253a078 fixed: in Big::FromDouble(double value) (32 bit version)
buffer overflow in referencing to UInt<2>
       (instead of m.table[2] should be m.table[0])
       this was used when: E=0 and F is nonzero (double "unnormalized" values)
       it produced incorrect mantissa (on about 8th decimal digit up)



git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@435 e52654a7-88a9-db11-a3e9-0013d4bc506e
2012-10-30 13:07:38 +00:00
6862321fad added: ttmath/ttmathdec.h
starting work on a Decimal template type


git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@381 e52654a7-88a9-db11-a3e9-0013d4bc506e
2012-02-04 16:26:11 +00:00
2e192969b0 changed: Big::FromString_ReadPartAfterComma()
now we're reading the all part as integer and 
         at the end we're dividing it by (base ^ how_many_digits_there_were)

         it's faster and should be a little accurate in some cases



git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@342 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-02-27 18:13:32 +00:00
e8daa77d75 changed: UInt::ToString() had O(n^2) complexity
where n was the number of digits to print
         now it has O(n)



git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@340 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-02-07 22:37:44 +00:00
231164f6ea 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
2011-01-30 17:34:42 +00:00
c51b2fdcc9 changed: small improvements in UInt::Pow() and Big::Pow()
git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@325 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-10-14 23:21:16 +00:00
84f34ebe52 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



git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@324 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-09-29 21:14:32 +00:00
9 changed files with 623 additions and 78 deletions

View File

@@ -1,3 +1,19 @@
Version 0.9.3 (2012.12.28):
* fixed: in Big::FromDouble(double value) (only 32 bit version)
buffer overflow in referencing to UInt<2>
this was used when 'value' was in so called "unnormalized" state
(E=0 and F is nonzero)
it produced incorrect mantissa (on about 8th decimal digit up)
* 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
* changed: small optimizations in UInt::ToString() and Big::FromString()
Version 0.9.2 (2010.09.23):
* fixed: Big::Add() sometimes incorrectly rounded the last bit from its mantissa
* fixed: Big::BigAnd() Big::BigOr() Big::BigXor() should have set NaN

View File

@@ -1,4 +1,4 @@
Copyright (c) 2006-2010, Tomasz Sowa
Copyright (c) 2006-2012, Tomasz Sowa
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2006-2010, Tomasz Sowa
* Copyright (c) 2006-2012, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -2832,10 +2832,14 @@ namespace ttmath
/*!
this is for convenience for the user
he can only use '#include <ttmath/ttmath.h>' even if he uses the parser
he can only use '#include <ttmath/ttmath.h>'
*/
#include "ttmathparser.h"
// Dec is not finished yet
//#include "ttmathdec.h"
#ifdef _MSC_VER
//warning C4127: conditional expression is constant

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2006-2010, Tomasz Sowa
* Copyright (c) 2006-2012, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -1571,7 +1571,7 @@ public:
return 0;
}
Big<exp, man> start(*this), start_temp;
Big<exp, man> start(*this);
Big<exp, man> result;
result.SetOne();
uint c = 0;
@@ -1586,8 +1586,7 @@ public:
if( pow.IsZero() )
break;
start_temp = start;
c += start.Mul(start_temp);
c += start.Mul(start);
}
*this = result;
@@ -1665,13 +1664,10 @@ public:
if( pow.IsSign() )
pow.Abs();
Big<exp, man> start(*this), start_temp;
Big<exp, man> start(*this);
Big<exp, man> result;
Big<exp, man> one;
Int<exp> e_one;
uint c = 0;
e_one.SetOne();
one.SetOne();
result = one;
@@ -1680,13 +1676,12 @@ public:
if( pow.Mod2() )
c += result.Mul(start);
c += pow.exponent.Sub( e_one ); // !! may use SubOne() here?
c += pow.exponent.SubOne();
if( pow < one )
break;
start_temp = start;
c += start.Mul(start_temp);
c += start.Mul(start);
}
*this = result;
@@ -2649,7 +2644,7 @@ public:
FromDouble_SetExpAndMan((temp.u[1] & 0x80000000u) != 0,
e - 1022 - man*TTMATH_BITS_PER_UINT + 1 - moved, 0,
m.table[1], m.table[2]);
m.table[1], m.table[0]);
}
else
{
@@ -4743,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<char_type>(conv.group));
@@ -4768,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<new_man.size() ; ++index, ++group)
{
if( group >= 3 )
if( group >= group_digits )
{
group = 0;
new_man.insert(index, 1, static_cast<char_type>(conv.group));
@@ -5117,19 +5120,14 @@ private:
uint FromString_ReadPartAfterComma( const char_type * & source, const Conv & conv, bool & value_read )
{
sint character;
uint c = 0, index = 1;
Big<exp, man> sum, part, power, old_value, base_( conv.base );
uint c = 0, power = 0;
UInt<1> power_;
Big<exp, man> sum, base_(conv.base);
// we don't remove any white characters here
// this is only to avoid getting a warning about an uninitialized object 'old_value' which GCC reports
// (in fact we will initialize it later when the condition 'testing' is fulfilled)
old_value.SetZero();
power.SetOne();
sum.SetZero();
for( ; true ; ++source, ++index )
for( ; sum.exponent.IsSign() || sum.exponent.IsZero() ; ++source )
{
if( conv.group!=0 && *source==static_cast<char>(conv.group) )
continue;
@@ -5141,30 +5139,13 @@ private:
value_read = true;
part = character;
if( power.Mul( base_ ) )
// there's no sens to add the next parts, but we can't report this
// as an error (this is only inaccuracy)
break;
if( part.Div( power ) )
break;
// every 5 iteration we make a test whether the value will be changed or not
// (character must be different from zero to this test)
bool testing = (character != 0 && (index % 5) == 0);
if( testing )
old_value = sum;
// there actually shouldn't be a carry here
c += sum.Add( part );
c += sum.Mul(base_);
c += sum.Add(character);
power += 1;
if( testing && old_value == sum )
// after adding 'part' the value has not been changed
// there's no sense to add any next parts
break;
if( power == 0 )
c += 1;
}
// we could break the parsing somewhere in the middle of the string,
@@ -5172,6 +5153,9 @@ private:
// we should set a correct value of 'source' now
for( ; Misc::CharToDigit(*source, conv.base) != -1 ; ++source );
power_ = power;
c += base_.Pow(power_);
c += sum.Div(base_);
c += Add(sum);
return (c==0)? 0 : 1;

419
ttmath/ttmathdec.h Normal file
View File

@@ -0,0 +1,419 @@
/*
* This file is a part of TTMath Bignum Library
* and is distributed under the (new) BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2012, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name Tomasz Sowa nor the names of contributors to this
* project may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef headerfilettmathdec
#define headerfilettmathdec
#include "ttmathtypes.h"
#include "ttmaththreads.h"
#include "ttmathuint.h"
namespace ttmath
{
template<uint value_size, uint dec_digits>
class Dec
{
public:
UInt<value_size> value;
unsigned char info;
/*!
Sign
the mask of a bit from 'info' which means that there is a sign
(when the bit is set)
*/
#define TTMATH_DEC_SIGN 128
/*!
Not a number
if this bit is set that there is not a valid number
*/
#define TTMATH_DEC_NAN 64
Dec()
{
info = TTMATH_DEC_NAN;
}
Dec(const char * s)
{
info = TTMATH_DEC_NAN;
FromString(s);
}
Dec<value_size, dec_digits> & operator=(const char * s)
{
FromString(s);
return *this;
}
uint FromString(const char * s, const char ** after_source = 0, bool * value_read = 0)
{
return FromStringBase(s, after_source, value_read);
}
void ToString(std::string & result) const
{
ToStringBase(result);
}
/*!
this method clears a specific bit in the 'info' variable
bit is one of:
*/
void ClearInfoBit(unsigned char bit)
{
info = info & (~bit);
}
/*!
this method sets a specific bit in the 'info' variable
bit is one of:
*/
void SetInfoBit(unsigned char bit)
{
info = info | bit;
}
/*!
this method returns true if a specific bit in the 'info' variable is set
bit is one of:
*/
bool IsInfoBit(unsigned char bit) const
{
return (info & bit) != 0;
}
bool IsNan() const
{
return IsInfoBit(TTMATH_DEC_NAN);
}
bool IsSign() const
{
return IsInfoBit(TTMATH_DEC_SIGN);
}
/*!
this method sets the sign
e.g.
-1 -> -1
2 -> -2
we do not check whether there is a zero or not, if you're using this method
you must be sure that the value is (or will be afterwards) different from zero
*/
void SetSign()
{
SetInfoBit(TTMATH_DEC_SIGN);
}
void SetNaN()
{
SetInfoBit(TTMATH_DEC_NAN);
}
void Abs()
{
ClearInfoBit(TTMATH_DEC_SIGN);
}
uint Add(const Dec<value_size, dec_digits> & arg)
{
uint c = 0;
if( IsSign() == arg.IsSign() )
{
c += value.Add(arg.value);
}
else
{
bool is_sign;
if( value > arg.value )
{
is_sign = IsSign();
value.Sub(arg.value);
}
else
{
is_sign = arg.IsSign();
UInt<value_size> temp(this->value);
value = arg.value;
value.Sub(temp);
}
is_sign ? SetSign() : Abs();
}
if( c )
SetNaN();
return (c==0)? 0 : 1;
}
/*
uint Sub(const Dec<value_size, dec_digits> & arg)
{
}
*/
private:
#ifndef TTMATH_MULTITHREADS
/*!
*/
void SetMultipler(UInt<value_size> & result)
{
// this guardian is initialized before the program runs (static POD type)
static int guardian = 0;
static UInt<value_size> multipler;
if( guardian == 0 )
{
multipler = 10;
multipler.Pow(dec_digits);
guardian = 1;
}
result = multipler;
}
#else
/*!
*/
void SetMultipler(UInt<value_size> & result)
{
// this guardian is initialized before the program runs (static POD type)
volatile static sig_atomic_t guardian = 0;
static UInt<value_size> * pmultipler;
// double-checked locking
if( guardian == 0 )
{
ThreadLock thread_lock;
// locking
if( thread_lock.Lock() )
{
static UInt<value_size> multipler;
if( guardian == 0 )
{
pmultipler = &multipler;
multipler = 10;
multipler.Pow(dec_digits);
guardian = 1;
}
}
else
{
// there was a problem with locking, we store the result directly in 'result' object
result = 10;
result.Pow(dec_digits);
return;
}
// automatically unlocking
}
result = *pmultipler;
}
#endif
/*!
an auxiliary method for converting from a string
*/
template<class char_type>
uint FromStringBase(const char_type * s, const char_type ** after_source = 0, bool * value_read = 0)
{
UInt<value_size> multipler;
const char_type * after;
uint c = 0;
info = 0;
Misc::SkipWhiteCharacters(s);
if( *s == '-' )
{
s += 1;
SetSign();
}
else
if( *s == '+' )
{
s += 1;
}
c += value.FromString(s, 10, &after, value_read);
if( after_source )
*after_source = after;
SetMultipler(multipler);
c += value.Mul(multipler);
if( *after == '.' )
c += FromStringBaseAfterComma(after+1, after_source);
if( c )
SetInfoBit(TTMATH_DEC_NAN);
return (c==0)? 0 : 1;
}
template<class char_type>
uint FromStringBaseAfterComma(const char_type * s, const char_type ** after_source = 0, bool * value_read = 0)
{
UInt<value_size> temp;
UInt<value_size> multipler;
sint z;
uint c = 0;
size_t i = dec_digits;
SetMultipler(multipler);
for( ; i>0 && (z=Misc::CharToDigit(*s, 10)) != -1 ; --i, ++s )
{
multipler.DivInt(10);
temp.SetZero();
if( value_read )
*value_read = true;
if( c == 0 )
{
temp.table[0] = z;
c += temp.Mul(multipler);
c += value.Add(temp);
}
}
if( i == 0 && (z=Misc::CharToDigit(*s, 10)) != -1 && z >= 5 )
c += value.AddOne();
if( after_source )
{
while( (z=Misc::CharToDigit(*s, 10)) != -1 )
s += 1;
*after_source = s;
}
return c;
}
template<class string_type>
void ToStringBase(string_type & result) const
{
if( IsNan() )
{
result = "NaN";
return;
}
value.ToStringBase(result, 10, IsSign());
if( dec_digits > 0 )
{
size_t size = result.size();
if( IsSign() && size > 0 )
size -= 1;
if( dec_digits >= size )
{
size_t zeroes = dec_digits - size + 1;
size_t start = IsSign() ? 1 : 0;
result.insert(start, zeroes, '0');
}
result.insert(result.end() - dec_digits, '.');
}
}
};
} // namespace
#endif

View File

@@ -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
@@ -1315,13 +1315,11 @@ private:
{
Int<value_size> temp(*this);
temp.Abs();
temp.UInt<value_size>::ToString(result, b);
result.insert(result.begin(), '-');
temp.UInt<value_size>::ToStringBase(result, b, true);
}
else
{
UInt<value_size>::ToString(result, b);
UInt<value_size>::ToStringBase(result, b, false);
}
}

View File

@@ -2755,6 +2755,18 @@ bool Calculated()
}
/*!
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
*/
void InitCGamma()
{
cgamma.InitAll();
}
};

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2006-2010, Tomasz Sowa
* Copyright (c) 2006-2012, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -72,7 +72,7 @@
*/
#define TTMATH_MAJOR_VER 0
#define TTMATH_MINOR_VER 9
#define TTMATH_REVISION_VER 2
#define TTMATH_REVISION_VER 3
#define TTMATH_PRERELEASE_VER 0
@@ -122,7 +122,7 @@
_M_IX86 defined by Visual Studio, Intel C/C++, Digital Mars and Watcom C/C++
amd64 architecture:
__x86_64__ defined by GNU C and Sun Studio
__x86_64__ defined by GNU C, CLANG (LLVM) and Sun Studio
_M_X64 defined by Visual Studio
asm version is available only for x86 or amd64 platforms
@@ -134,7 +134,8 @@
#if !defined _MSC_VER && !defined __GNUC__
/*!
another compilers than MS VC or GCC by default use no asm version
another compilers than MS VC or GCC or CLANG (LLVM) by default use no asm version
(CLANG defines __GNUC__ too)
*/
#define TTMATH_NOASM
#endif
@@ -465,6 +466,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 +492,7 @@ namespace ttmath
comma = '.';
comma2 = ',';
group = 0;
group_digits = 3;
group_exp = 0;
}
};

View File

@@ -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
@@ -1260,9 +1260,18 @@ private:
UInt<ss_size*2> res;
Mul2Big2<ss_size>(ss1, ss2, res);
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-compare"
#endif
for(uint i=0 ; i<ss_size*2 ; ++i)
result[i] = res.table[i];
#ifdef __clang__
#pragma clang diagnostic pop
#endif
return;
}
else
@@ -1355,10 +1364,18 @@ private:
Mul3Big2<first_size>(temp.table, temp2.table, z1.table);
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-compare"
#endif
// clearing the rest of z1
for(i=first_size*2 ; i<first_size*3 ; ++i)
z1.table[i] = 0;
#ifdef __clang__
#pragma clang diagnostic pop
#endif
if( xc )
{
@@ -1375,9 +1392,18 @@ private:
if( xc && yc )
{
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-compare"
#endif
for( i=first_size*2 ; i<first_size*3 ; ++i )
if( ++z1.table[i] != 0 )
break; // break if there was no carry
break; // break if there was no carry
#ifdef __clang__
#pragma clang diagnostic pop
#endif
}
// z1 = z1 - z2
@@ -1396,11 +1422,20 @@ private:
uint z1_size = result_size - first_size;
TTMATH_ASSERT( z1_size <= first_size*3 )
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-compare"
#endif
for(i=z1_size ; i<first_size*3 ; ++i)
{
TTMATH_ASSERT( z1.table[i] == 0 )
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif
c = AddVector(result+first_size, z1.table, result_size-first_size, z1_size, result+first_size);
TTMATH_ASSERT(c==0)
}
@@ -2370,7 +2405,7 @@ public:
// we don't define zero^zero
return 2;
UInt<value_size> start(*this), start_temp;
UInt<value_size> start(*this);
UInt<value_size> result;
result.SetOne();
uint c = 0;
@@ -2384,9 +2419,7 @@ public:
if( pow.IsZero() )
break;
start_temp = start;
// in the second Mul algorithm we can use start.Mul(start) directly (there is no TTMATH_ASSERT_REFERENCE there)
c += start.Mul(start_temp);
c += start.Mul(start);
}
*this = result;
@@ -2507,10 +2540,18 @@ public:
*/
bool IsOnlyTheHighestBitSet() const
{
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-compare"
#endif
for(uint i=0 ; i<value_size-1 ; ++i)
if( table[i] != 0 )
return false;
#ifdef __clang__
#pragma clang diagnostic pop
#endif
if( table[value_size-1] != TTMATH_UINT_HIGHEST_BIT )
return false;
@@ -3206,36 +3247,98 @@ public:
private:
protected:
/*!
an auxiliary method for converting into the string
it returns the log (with the base 2) from x
where x is in <2;16>
*/
double ToStringLog2(uint x) const
{
static double log_tab[] = {
1.000000000000000000,
0.630929753571457437,
0.500000000000000000,
0.430676558073393050,
0.386852807234541586,
0.356207187108022176,
0.333333333333333333,
0.315464876785728718,
0.301029995663981195,
0.289064826317887859,
0.278942945651129843,
0.270238154427319741,
0.262649535037193547,
0.255958024809815489,
0.250000000000000000
};
if( x<2 || x>16 )
return 0;
return log_tab[x-2];
}
public:
/*!
an auxiliary method for converting to a string
it's used from Int::ToString() too (negative is set true then)
*/
template<class string_type>
void ToStringBase(string_type & result, uint b = 10) const
void ToStringBase(string_type & result, uint b = 10, bool negative = false) const
{
UInt<value_size> temp( *this );
UInt<value_size> temp(*this);
uint rest, table_id, index, digits;
double digits_d;
char character;
uint rem;
result.clear();
if( b<2 || b>16 )
return;
if( !FindLeadingBit(table_id, index) )
{
result = '0';
return;
}
if( negative )
result = '-';
digits_d = table_id; // for not making an overflow in uint type
digits_d *= TTMATH_BITS_PER_UINT;
digits_d += index + 1;
digits_d *= ToStringLog2(b);
digits = static_cast<uint>(digits_d) + 3; // plus some epsilon
if( result.capacity() < digits )
result.reserve(digits);
do
{
temp.DivInt(b, &rem);
character = static_cast<char>( Misc::DigitToChar(rem) );
result.insert(result.begin(), character);
temp.DivInt(b, &rest);
character = static_cast<char>(Misc::DigitToChar(rest));
result.insert(result.end(), character);
}
while( !temp.IsZero() );
return;
size_t i1 = negative ? 1 : 0; // the first is a hyphen (when negative is true)
size_t i2 = result.size() - 1;
for( ; i1 < i2 ; ++i1, --i2 )
{
char tempc = static_cast<char>(result[i1]);
result[i1] = result[i2];
result[i2] = tempc;
}
}
public:
/*!
this method converts the value to a string with a base equal 'b'
@@ -3310,7 +3413,7 @@ private:
{
temp.table[0] = z;
c += Mul(base);
c += Mul(base); // !! IMPROVE ME: there can be used MulInt here
c += Add(temp);
}
}
@@ -3976,7 +4079,7 @@ public:
/*
following methods are defined in:
Following methods are defined in:
ttmathuint_x86.h
ttmathuint_x86_64.h
ttmathuint_noasm.h