added some missing methods: ToUInt, ToInt, FromUInt, FromInt in Big<> class

git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@317 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2010-09-23 18:56:55 +00:00
parent a40e951923
commit 362207e2f1
3 changed files with 106 additions and 17 deletions

View File

@ -2459,6 +2459,8 @@ public:
if( IsSign() ) if( IsSign() )
return 1; return 1;
return 0;
} }
@ -2835,18 +2837,18 @@ private:
The first bit is the sign bit, S, the next eight bits are the exponent bits, 'E', The first bit is the sign bit, S, the next eight bits are the exponent bits, 'E',
and the final 23 bits are the fraction 'F': and the final 23 bits are the fraction 'F':
S EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF S EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF
0 1 8 9 31 0 1 8 9 31
The value V represented by the word may be determined as follows: The value V represented by the word may be determined as follows:
* If E=255 and F is nonzero, then V=NaN ("Not a number") * If E=255 and F is nonzero, then V=NaN ("Not a number")
* If E=255 and F is zero and S is 1, then V=-Infinity * If E=255 and F is zero and S is 1, then V=-Infinity
* If E=255 and F is zero and S is 0, then V=Infinity * If E=255 and F is zero and S is 0, then V=Infinity
* If 0<E<255 then V=(-1)**S * 2 ** (E-127) * (1.F) where "1.F" is intended to represent * If 0<E<255 then V=(-1)**S * 2 ** (E-127) * (1.F) where "1.F" is intended to represent
the binary number created by prefixing F with an implicit leading 1 and a binary point. the binary number created by prefixing F with an implicit leading 1 and a binary point.
* If E=0 and F is nonzero, then V=(-1)**S * 2 ** (-126) * (0.F) These are "unnormalized" values. * If E=0 and F is nonzero, then V=(-1)**S * 2 ** (-126) * (0.F) These are "unnormalized" values.
* If E=0 and F is zero and S is 1, then V=-0 * If E=0 and F is zero and S is 1, then V=-0
* If E=0 and F is zero and S is 0, then V=0 * If E=0 and F is zero and S is 0, then V=0
*/ */
bool IsInf(float value) const bool IsInf(float value) const
@ -3153,8 +3155,48 @@ public:
FromFloat(value); FromFloat(value);
} }
#ifdef TTMATH_PLATFORM32 #ifdef TTMATH_PLATFORM32
/*!
this method converts 'this' into 'result' (64 bit unsigned integer)
if the value is too big this method returns a carry (1)
*/
uint ToUInt(ulint & result) const
{
UInt<2> temp; // 64 bits container
uint c = ToUInt(temp);
temp.ToUInt(result);
return c;
}
/*!
this method converts 'this' into 'result' (64 bit unsigned integer)
if the value is too big this method returns a carry (1)
*/
uint ToInt(ulint & result) const
{
return ToUInt(result);
}
/*!
this method converts 'this' into 'result' (64 bit unsigned integer)
if the value is too big this method returns a carry (1)
*/
uint ToInt(slint & result) const
{
Int<2> temp; // 64 bits container
uint c = ToInt(temp);
temp.ToInt(result);
return c;
}
/*! /*!
a method for converting 'ulint' (64bit unsigned integer) to this class a method for converting 'ulint' (64bit unsigned integer) to this class
@ -3293,6 +3335,56 @@ public:
#ifdef TTMATH_PLATFORM64 #ifdef TTMATH_PLATFORM64
/*!
this method converts 'this' into 'result' (32 bit unsigned integer)
***this method is created only on a 64bit platform***
if the value is too big this method returns a carry (1)
*/
uint ToUInt(unsigned int & result) const
{
uint result_uint;
uint c = ToUInt(result_uint);
result = (unsigned int)result_uint;
if( c || result_uint != uint(result) )
return 1;
return 0;
}
/*!
this method converts 'this' into 'result' (32 bit unsigned integer)
***this method is created only on a 64bit platform***
if the value is too big this method returns a carry (1)
*/
uint ToInt(unsigned int & result) const
{
return ToUInt(result);
}
/*!
this method converts 'this' into 'result' (32 bit signed integer)
***this method is created only on a 64bit platform***
if the value is too big this method returns a carry (1)
*/
uint ToInt(signed int & result) const
{
sint result_sint;
uint c = ToInt(result_sint);
result = (signed int)result_sint;
if( c || result_sint != sint(result) )
return 1;
return 0;
}
/* /*
this method converts 32 bit unsigned int to this class this method converts 32 bit unsigned int to this class
***this method is created only on a 64bit platform*** ***this method is created only on a 64bit platform***

View File

@ -2850,7 +2850,6 @@ public:
*/ */
uint FromUInt(unsigned int i) uint FromUInt(unsigned int i)
{ {
// !! need testing
return FromUInt(uint(i)); return FromUInt(uint(i));
} }
@ -2860,7 +2859,6 @@ public:
*/ */
uint FromInt(unsigned int i) uint FromInt(unsigned int i)
{ {
// !! need testing
return FromUInt(uint(i)); return FromUInt(uint(i));
} }
@ -2871,7 +2869,6 @@ public:
*/ */
uint FromInt(signed int i) uint FromInt(signed int i)
{ {
// !! need testing
return FromInt(sint(i)); return FromInt(sint(i));
} }

View File

@ -36,9 +36,9 @@
; ;
; ;
; compile with debug info: ml64.exe /Zd /Zi ttmathuint_x86_64_msvc.asm ; compile with debug info: ml64.exe /c /Zd /Zi ttmathuint_x86_64_msvc.asm
; compile without debug info: ml64.exe ttmathuint_x86_64_msvc.asm ; compile without debug info: ml64.exe /c ttmathuint_x86_64_msvc.asm
; this create ttmathuint_x86_64_msvc.obj file which can be linked with your program ; this creates ttmathuint_x86_64_msvc.obj file which can be linked with your program
; ;
PUBLIC ttmath_adc_x64 PUBLIC ttmath_adc_x64