summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main.cpp8
-rw-r--r--src/number.cpp31
-rw-r--r--src/unitnumber.cpp6
3 files changed, 30 insertions, 15 deletions
diff --git a/src/main.cpp b/src/main.cpp
index cd38438..50b143e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -11,10 +11,18 @@
11#include <bu/streamstack.h> 11#include <bu/streamstack.h>
12using namespace Bu; 12using namespace Bu;
13 13
14#define mathTestP( sc, anum, op, bnum, answ ) \
15 Bu::println(">>%1<<").arg((Number(anum, sc) op Number(bnum, sc)).toString())
16
14int main( int argc, char *argv[] ) 17int main( int argc, char *argv[] )
15{ 18{
16 try 19 try
17 { 20 {
21 mathTestP( 5, "63.6", /, "504", "0.12619" );
22 mathTestP( 5, "63.61", /, "504", "0.12621" );
23 mathTestP( 7, "63.610123", /, "5041", "0.12621" );
24 mathTestP( 7, "63.610123", /, "50412", "0.12621" );
25// return 0;
18 Options opt( argc, argv ); 26 Options opt( argc, argv );
19 27
20 println("CliC - 0.08"); 28 println("CliC - 0.08");
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 );
diff --git a/src/unitnumber.cpp b/src/unitnumber.cpp
index 92cf1b7..fc56bf6 100644
--- a/src/unitnumber.cpp
+++ b/src/unitnumber.cpp
@@ -252,6 +252,8 @@ void UnitNumber::radix1()
252 252
253#define mathTestS( sc, anum, op, bnum, answ ) \ 253#define mathTestS( sc, anum, op, bnum, answ ) \
254 unitTest( (Number(anum, sc) op Number(bnum, sc)).toString() == answ ) 254 unitTest( (Number(anum, sc) op Number(bnum, sc)).toString() == answ )
255#define mathTestP( sc, anum, op, bnum, answ ) \
256 Bu::println(">>%1<<").arg((Number(anum, sc) op Number(bnum, sc)).toString())
255 257
256void UnitNumber::fraction1() 258void UnitNumber::fraction1()
257{ 259{
@@ -261,7 +263,9 @@ void UnitNumber::fraction1()
261 mathTestS( 8, "123.456", -, "0.987", "122.469" ); 263 mathTestS( 8, "123.456", -, "0.987", "122.469" );
262 mathTestS( 8, "123.456", *, "0.987", "121.851072" ); 264 mathTestS( 8, "123.456", *, "0.987", "121.851072" );
263 mathTestS( 8, "123.456", /, "0.987", "125.08206686" ); 265 mathTestS( 8, "123.456", /, "0.987", "125.08206686" );
264 266
267 mathTestP( 5, "63.6", /, "504", "0.12619" );
268 mathTestS( 5, "63.6", /, "504", "0.12619" );
265 mathTestS( 8, "12", /, "4", "3" ); 269 mathTestS( 8, "12", /, "4", "3" );
266 mathTestS( 100, "9", /, "1.9", "4.7368421052631578947368421052631578947368421052631578947368421052631578947368421052631578947368421052" ); 270 mathTestS( 100, "9", /, "1.9", "4.7368421052631578947368421052631578947368421052631578947368421052631578947368421052631578947368421052" );
267} 271}