summaryrefslogtreecommitdiff
path: root/src/number.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/number.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/number.cpp b/src/number.cpp
index eb4d01d..cab7f46 100644
--- a/src/number.cpp
+++ b/src/number.cpp
@@ -358,6 +358,17 @@ void Number::set( const Number &sNum )
358 iRadix = sNum.iRadix; 358 iRadix = sNum.iRadix;
359} 359}
360 360
361void Number::set( int32_t iNum )
362{
363 aFrac.zero();
364 aInt.clear();
365 while( iNum > 0 )
366 {
367 aInt.append( iNum%iRadix );
368 iNum /= iRadix;
369 }
370}
371
361void Number::divide( const Number &rhs, Number &q, Number &r ) const 372void Number::divide( const Number &rhs, Number &q, Number &r ) const
362{ 373{
363 if( rhs.iScale > 0 ) 374 if( rhs.iScale > 0 )
@@ -598,6 +609,25 @@ int32_t Number::toInt32() const
598 return ret; 609 return ret;
599} 610}
600 611
612Number Number::toRadix( int iNewRadix, int iNewScale ) const
613{
614 if( iNewScale < 0 )
615 iNewScale = iScale;
616 Number ret( iNewScale, iNewRadix );
617
618 Number me( 0, iRadix );
619 me = *this;
620 Number n( 0, iRadix );
621 n.set( iNewRadix );
622 while( !me.isZero() )
623 {
624 ret.aInt.append( (me%n).toInt32() );
625 me = me / n;
626 }
627
628 return ret;
629}
630
601Number Number::add( const Number &rhs, bool bSub ) const 631Number Number::add( const Number &rhs, bool bSub ) const
602{ 632{
603 Number ret( Bu::buMax(iScale,rhs.iScale), iRadix ); 633 Number ret( Bu::buMax(iScale,rhs.iScale), iRadix );