summaryrefslogtreecommitdiff
path: root/src/number.cpp
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2013-05-09 15:24:11 -0600
committerMike Buland <mike@xagasoft.com>2013-05-09 15:24:11 -0600
commitce68e816bd82612c14f3492e8bc969da9bfab06c (patch)
treebe50fa63ce720ecde2748df3df83f38a284c3ff6 /src/number.cpp
parent722e0ef0ea2624c1cd9bd5ca69833e37dc09f97f (diff)
downloadclic-ce68e816bd82612c14f3492e8bc969da9bfab06c.tar.gz
clic-ce68e816bd82612c14f3492e8bc969da9bfab06c.tar.bz2
clic-ce68e816bd82612c14f3492e8bc969da9bfab06c.tar.xz
clic-ce68e816bd82612c14f3492e8bc969da9bfab06c.zip
Added better filtering in Number::set, and cli options.
The command line options let you set the initial radix/scale, and there's a function te test if any number is prime, that's fun.
Diffstat (limited to 'src/number.cpp')
-rw-r--r--src/number.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/number.cpp b/src/number.cpp
index 062e368..eb4d01d 100644
--- a/src/number.cpp
+++ b/src/number.cpp
@@ -306,15 +306,22 @@ void Number::set( const Bu::String &sNum )
306 } 306 }
307 for( ; iEnd < sNum.getSize() && sNum[iEnd] == '0'; iEnd++ ) { } 307 for( ; iEnd < sNum.getSize() && sNum[iEnd] == '0'; iEnd++ ) { }
308 308
309 int iDigit;
309 for( int j = iPt-1; j >= iEnd; j-- ) 310 for( int j = iPt-1; j >= iEnd; j-- )
310 { 311 {
311// Bu::println(" -> '%1'").arg( sNum[j] ); 312// Bu::println(" -> '%1'").arg( sNum[j] );
312 if( sNum[j] == '.' ) 313 if( sNum[j] == '.' )
313 break; 314 break;
314 if( sNum[j] >= '0' && sNum[j] <= '9' ) 315 if( sNum[j] >= '0' && sNum[j] <= '9' )
315 aInt.append( sNum[j]-'0' ); 316 iDigit = sNum[j]-'0';
316 else 317 else
317 aInt.append( sNum[j]-'a'+10 ); 318 iDigit = sNum[j]-'a'+10;
319 if( iDigit < 0 || iDigit >= iRadix )
320 throw Bu::ExceptionBase(Bu::String(
321 "Invalid character '%1' in Number::set").arg(sNum[j]).
322 end().getStr()
323 );
324 aInt.append( iDigit );
318 } 325 }
319 326
320 if( iScale > 0 ) 327 if( iScale > 0 )
@@ -324,9 +331,16 @@ void Number::set( const Bu::String &sNum )
324 { 331 {
325// Bu::println(" => '%1'").arg( sNum[j] ); 332// Bu::println(" => '%1'").arg( sNum[j] );
326 if( sNum[j] >= '0' && sNum[j] <= '9' ) 333 if( sNum[j] >= '0' && sNum[j] <= '9' )
327 aFrac.set( iFrac++, sNum[j]-'0' ); 334 iDigit = sNum[j]-'0';
328 else 335 else
329 aFrac.set( iFrac++, sNum[j]-'a'+10 ); 336 iDigit = sNum[j]-'a'+10;
337
338 if( iDigit < 0 || iDigit >= iRadix )
339 throw Bu::ExceptionBase(Bu::String(
340 "Invalid character '%1' in Number::set").arg(sNum[j]).
341 end().getStr()
342 );
343 aFrac.set( iFrac++, iDigit );
330 if( iFrac >= iScale ) 344 if( iFrac >= iScale )
331 break; 345 break;
332 } 346 }