From eda2bffe27415d28813badc5db572d1e4b20c3de Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 16 Apr 2013 14:53:02 -0600 Subject: Added formatter for Number. I'm a little embarassed that I didn't do this from the start, made the code so much easier to read. --- src/main.cpp | 130 ++++++++++++++--------------------------------------------- 1 file changed, 31 insertions(+), 99 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 6674075..4454c08 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,164 +38,101 @@ void numbertest1() Number a("1000902491523000321"); Number b("3004392012498000700"); - println("%1 + %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a + b).toString() ); + println("%1 + %2 = %3").arg( a ).arg( b ).arg( a + b ); - println("%1 * %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a * b).toString() ); + println("%1 * %2 = %3").arg( a ).arg( b ).arg( a * b ); a = "-872"; b = "123"; - println("%1 + %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a + b).toString() ); + println("%1 + %2 = %3").arg( a ).arg( b ).arg( a + b ); a = "728"; b = "-51"; - println("%1 + %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a + b).toString() ); + println("%1 + %2 = %3").arg( a ).arg( b ).arg( a + b ); a = "44"; b = "-55"; - println("%1 + %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a + b).toString() ); + println("%1 + %2 = %3").arg( a ).arg( b ).arg( a + b ); a = "44"; b = "-66"; - println("%1 + %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a + b).toString() ); + println("%1 + %2 = %3").arg( a ).arg( b ).arg( a + b ); a = "44"; b = "-66"; - println("%1 - %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a - b).toString() ); + println("%1 - %2 = %3").arg( a ).arg( b ).arg( a - b ); a = "44"; b = "66"; - println("%1 - %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a - b).toString() ); + println("%1 - %2 = %3").arg( a ).arg( b ).arg( a - b ); a = "7814"; b = "24"; - println("%1 * %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a * b).toString() ); + println("%1 * %2 = %3").arg( a ).arg( b ).arg( a * b ); a = "12345"; b = "678"; - println("%1 * %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a * b).toString() ); + println("%1 * %2 = %3").arg( a ).arg( b ).arg( a * b ); a = "3592846"; b = "944634757"; - println("%1 * %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a * b).toString() ); + println("%1 * %2 = %3").arg( a ).arg( b ).arg( a * b ); a = "3592846"; b = ""; - println("%1 * %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a * b).toString() ); + println("%1 * %2 = %3").arg( a ).arg( b ).arg( a * b ); a = "123"; b = "-45"; - println("%1 * %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a * b).toString() ); + println("%1 * %2 = %3").arg( a ).arg( b ).arg( a * b ); a = "-123"; b = "45"; - println("%1 * %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a * b).toString() ); + println("%1 * %2 = %3").arg( a ).arg( b ).arg( a * b ); a = "-123"; b = "-45"; - println("%1 * %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a * b).toString() ); + println("%1 * %2 = %3").arg( a ).arg( b ).arg( a * b ); a = "123"; b = "45"; - println("%1 / %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a / b).toString() ); + println("%1 / %2 = %3").arg( a ).arg( b ).arg( a / b ); a = "12345"; b = "45"; - println("%1 / %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a / b).toString() ); + println("%1 / %2 = %3").arg( a ).arg( b ).arg( a / b ); a = "3007103450821050020096034077958224700"; b = "898239467"; - println("%1 / %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a / b).toString() ); - println("%1 %% %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a % b).toString() ); + println("%1 / %2 = %3").arg( a ).arg( b ).arg( a / b ); + println("%1 %% %2 = %3").arg( a ).arg( b ).arg( a % b ); a = "983429807324875233421784598754987439873472349875329853298732"; b = "18446744073709551615"; - println("%1 / %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a / b).toString() ); - println("%1 %% %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a % b).toString() ); + println("%1 / %2 = %3").arg( a ).arg( b ).arg( a / b ); + println("%1 %% %2 = %3").arg( a ).arg( b ).arg( a % b ); } #define compcheck( anum, op, bnum ) \ a = #anum; b = #bnum; \ - println("%4: %1 " #op " %2 = %3").arg( a.toString() ).arg( b.toString() ). \ + println("%4: %1 " #op " %2 = %3").arg( a ).arg( b ). \ arg( a op b ).arg( ((a op b) == (anum op bnum)) ? "pass" : "fail" ) void numbertestcomp() @@ -327,21 +264,16 @@ void radixtest() a = "f8a72bce3"; b = "9ea8cb3"; println("%1 + %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a + b).toString() ); + arg( a ). + arg( b ). + arg( (a + b) ); println("%1 - %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a - b).toString() ); - println("%1 / %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a / b).toString() ); - println("%1 * %2 = %3"). - arg( a.toString() ). - arg( b.toString() ). - arg( (a * b).toString() ); + arg( a ). + arg( b ). + arg( (a - b) ); + println("%1 / %2 = %3").arg( a ).arg( b ). + arg( (a / b) ); + println("%1 * %2 = %3").arg( a ).arg( b ).arg( (a * b) ); } int main( int , char *[] ) -- cgit v1.2.3