fixed: template Big::FromBig(const Big<another_exp, another_man> & another)

didn't correctly set the exponent (when the mantisses had different size -
       when 'man' was different from 'another_man')
       this had impact on operator= too
       sample:
       Big<2,3> a = 100;
       Big<3,5> b;
       b = a; // b had a wrong value


git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@106 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2009-03-24 20:34:33 +00:00
parent 460608859c
commit 3899b8631c
2 changed files with 27 additions and 5 deletions

View File

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

View File

@ -1630,17 +1630,39 @@ public:
uint man_len_min = (man < another_man)? man : another_man;
uint i;
uint c = 0;
for( i = 0 ; i<man_len_min ; ++i )
mantissa.table[man-1-i] = another.mantissa.table[another_man-1-i];
for( ; i<man ; ++i )
mantissa.table[man-1-i] = 0;
// mantissa is standardized
//c += Standardizing();
return 0;
// MS Visual Express 2005 reports a warning (in the lines with 'uint man_diff = ...'):
// warning C4307: '*' : integral constant overflow
// but we're using 'if( man > another_man )' and 'if( man < another_man )' and there'll be no such a situation here
#pragma warning( disable: 4307 )
if( man > another_man )
{
uint man_diff = (man - another_man) * TTMATH_BITS_PER_UINT;
c += exponent.SubInt(man_diff, 0);
}
else
if( man < another_man )
{
uint man_diff = (another_man - man) * TTMATH_BITS_PER_UINT;
c += exponent.AddInt(man_diff, 0);
}
#pragma warning( default: 4307 )
// mantissa doesn't have to be standardized (either the highest bit is set or all bits are equal zero)
CorrectZero();
return (c == 0 )? 0 : 1;
}