summaryrefslogtreecommitdiff
path: root/src/number.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/number.cpp31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/number.cpp b/src/number.cpp
index 1b0efdc..b4cfaf2 100644
--- a/src/number.cpp
+++ b/src/number.cpp
@@ -404,7 +404,6 @@ void Number::divide( const Number &rhs, Number &q, Number &r ) const
404 newbase.aFrac.set( j+iOff, aFrac.get( j ) ); 404 newbase.aFrac.set( j+iOff, aFrac.get( j ) );
405 } 405 }
406 406
407// Bu::println("Conv %1 => %2 (iOff = %3)").arg( rhs ).arg( newrhs ).arg( iOff );
408// Bu::println("Conv %1 => %2 (iOff = %3)").arg( *this ).arg( newbase ).arg( iOff ); 407// Bu::println("Conv %1 => %2 (iOff = %3)").arg( *this ).arg( newbase ).arg( iOff );
409 408
410 newbase.divide( newrhs, q, r ); 409 newbase.divide( newrhs, q, r );
@@ -424,15 +423,11 @@ void Number::divide( const Number &rhs, Number &q, Number &r ) const
424 423
425 int iAnchor = r.aInt.getSize()-iMinWidth; 424 int iAnchor = r.aInt.getSize()-iMinWidth;
426 int iSample = iMinWidth; 425 int iSample = iMinWidth;
426 int iAnchorOffset = 0;
427 do 427 do
428 { 428 {
429// Bu::println("%1\n-----").arg( r.aInt.toString() ); 429// Bu::println("%1\n-----").arg( r.aInt.toString() );
430 Number sub( 0, iRadix ); 430 Number sub( 0, iRadix );
431 if( iAnchor < 0 )
432 {
433 sub = r;
434 sub.aInt.insert(0,0);
435 }
436 for(;;) 431 for(;;)
437 { 432 {
438// Bu::println(" -> Anchor: %1, Sample: %2").arg( iAnchor ).arg( iSample ); 433// Bu::println(" -> Anchor: %1, Sample: %2").arg( iAnchor ).arg( iSample );
@@ -442,12 +437,19 @@ void Number::divide( const Number &rhs, Number &q, Number &r ) const
442 } 437 }
443 else 438 else
444 { 439 {
445/* sub.aInt.clear(); 440 int iMyAnchor = iAnchor-iAnchorOffset;
446 for( int j = iAnchor; j < r.aInt.getSize(); j++ ) 441// Bu::println(" -> starting with: %1").arg( r );
442 if( iSample+iMyAnchor > 0 )
443 {
444 sub.aInt.set( r.aInt, 0, iSample+iMyAnchor );
445 for( int j = 0; j < iSample-(iSample+iMyAnchor); j++ )
446 sub.aInt.insert(0, r.aFrac[j]);
447 }
448 else
447 { 449 {
448 sub.aInt.append( r.digit( j ) ); 450 for( int j = 0; j < iSample; j++ )
451 sub.aInt.insert(0, r.aFrac[j-(iMyAnchor+iSample)]);
449 } 452 }
450 */
451 } 453 }
452// Bu::println("%1\n%2\n----").arg( sub.toString() ).arg( rhs.toString() ); 454// Bu::println("%1\n%2\n----").arg( sub.toString() ).arg( rhs.toString() );
453 if( sub < rhs ) 455 if( sub < rhs )
@@ -461,13 +463,14 @@ void Number::divide( const Number &rhs, Number &q, Number &r ) const
461// Bu::println("[Inner exit] Complete: q = %1, r = %2").arg( q.toString() ).arg( r.toString() ); 463// Bu::println("[Inner exit] Complete: q = %1, r = %2").arg( q.toString() ).arg( r.toString() );
462 return; 464 return;
463 } 465 }
464 sub.aInt.insert(0, 0);
465 } 466 }
466 } 467 }
467 else 468 else
468 break; 469 break;
469 } 470 }
470 471
472 iAnchorOffset = iAnchor;
473
471 Number x( 0, iRadix ); 474 Number x( 0, iRadix );
472 int iRes = -1; 475 int iRes = -1;
473// Bu::println("{x = %1, sub=%2, rhs=%4, iRes=%3}").arg( x ).arg(sub).arg(iRes).arg(rhs); 476// Bu::println("{x = %1, sub=%2, rhs=%4, iRes=%3}").arg( x ).arg(sub).arg(iRes).arg(rhs);
@@ -506,10 +509,10 @@ void Number::divide( const Number &rhs, Number &q, Number &r ) const
506 q.aFrac.set( -1-iAnchor, iRes ); 509 q.aFrac.set( -1-iAnchor, iRes );
507 510
508 iSample = iMinWidth; 511 iSample = iMinWidth;
509 if( iAnchor > 0 ) 512// if( iAnchor > 0 )
510 iAnchor -= rhs.aInt.getSize()-x.aInt.getSize(); 513 iAnchor -= rhs.aInt.getSize()-x.aInt.getSize();
511 else 514// else
512 iAnchor--; 515// iAnchor--;
513// iAnchor = r.aInt.getSize()-iMinWidth; 516// iAnchor = r.aInt.getSize()-iMinWidth;
514// Bu::println(" -> new Anchor: %1, Sample: %2").arg( iAnchor ). 517// Bu::println(" -> new Anchor: %1, Sample: %2").arg( iAnchor ).
515// arg( iSample ); 518// arg( iSample );