From 669698c6d781147247599b59c3764414d0e25c09 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sun, 22 Jul 2007 23:20:09 +0000 Subject: [PATCH] added: method Big::FromDouble(double) which converts from standard double into a Big<> (only 32bit platforms) git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@47 e52654a7-88a9-db11-a3e9-0013d4bc506e --- ttmath/ttmathbig.h | 128 ++++++++++++++++++++++++++++++++++++++++++++ ttmath/ttmathuint.h | 68 +++++++++++------------ 2 files changed, 162 insertions(+), 34 deletions(-) diff --git a/ttmath/ttmathbig.h b/ttmath/ttmathbig.h index cd3e733..da4efec 100644 --- a/ttmath/ttmathbig.h +++ b/ttmath/ttmathbig.h @@ -1682,6 +1682,134 @@ public: } + + /*! + this method converts from standard double into this class + + standard double means IEEE-754 floating point value with 64 bits + it is as follows (from http://www.psc.edu/general/software/packages/ieee/ieee.html): + + The IEEE double precision floating point standard representation requires + a 64 bit word, which may be represented as numbered from 0 to 63, left to + right. The first bit is the sign bit, S, the next eleven bits are the + exponent bits, 'E', and the final 52 bits are the fraction 'F': + + S EEEEEEEEEEE FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF + 0 1 11 12 63 + + The value V represented by the word may be determined as follows: + + * If E=2047 and F is nonzero, then V=NaN ("Not a number") + * If E=2047 and F is zero and S is 1, then V=-Infinity + * If E=2047 and F is zero and S is 0, then V=Infinity + * If 0> 20; + unsigned int m1 = ((temp.u[1] & 0xFFFFFu) << 11) | (temp.u[0] >> 21); + unsigned int m2 = temp.u[0] << 11; + + if( e == 2047 ) + { + // If E=2047 and F is nonzero, then V=NaN ("Not a number") + // If E=2047 and F is zero and S is 1, then V=-Infinity + // If E=2047 and F is zero and S is 0, then V=Infinity + + // at the moment we do not support NaN, -Infinity and +Infinity + + SetZero(); + } + else + if( e > 0 ) + { + // If 0 1 ) + { + mantissa.table[man-1] = m1 | mhighest; + mantissa.table[man-2] = m2; + + for(unsigned int i=0 ; i>= shift; - - table[table_id] ^= mask; - } - else - table[0] = 1; + void BitNot2() + { + uint table_id, index; + + if( FindLeadingBit(table_id, index) ) + { + for(uint x=0 ; x>= shift; + + table[table_id] ^= mask; + } + else + table[0] = 1; }