From 3899b8631c82df966da1c651dc93d9d430177c3d Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Tue, 24 Mar 2009 20:34:33 +0000 Subject: [PATCH] fixed: template Big::FromBig(const Big & 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 --- COPYRIGHT | 2 +- ttmath/ttmathbig.h | 30 ++++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/COPYRIGHT b/COPYRIGHT index e2af1c2..0e1660a 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -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 diff --git a/ttmath/ttmathbig.h b/ttmath/ttmathbig.h index c3a727e..f319f52 100644 --- a/ttmath/ttmathbig.h +++ b/ttmath/ttmathbig.h @@ -1630,17 +1630,39 @@ public: uint man_len_min = (man < another_man)? man : another_man; uint i; + uint c = 0; for( i = 0 ; i 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; }