@@ -385,29 +385,40 @@ Deno.test('mod', () => {
385
385
386
386
Deno . test ( 'pow' , ( ) => {
387
387
const vectors : ( { a : Decimal ; b : number } & ( { success : true ; output : Decimal } | { success : false } ) ) [ ] = [
388
+ { a : Decimal . from ( 2 ) , b : 3 , success : true , output : Decimal . from ( 8 ) } ,
389
+ { a : Decimal . from ( 2 ) , b : 2 , success : true , output : Decimal . from ( 4 ) } ,
388
390
{ a : Decimal . from ( 2 ) , b : 1 , success : true , output : Decimal . from ( 2 ) } ,
389
391
{ a : Decimal . from ( 2 ) , b : 0 , success : true , output : Decimal . from ( 1 ) } ,
390
392
{ a : Decimal . from ( 2 ) , b : 2 , success : true , output : Decimal . from ( 4 ) } ,
391
393
{ a : Decimal . from ( 2 ) , b : - 1 , success : true , output : Decimal . from ( 0.5 ) } ,
392
394
{ a : Decimal . from ( 2 ) , b : - 2 , success : true , output : Decimal . from ( 0.25 ) } ,
395
+ { a : Decimal . from ( 2 ) , b : - 3 , success : true , output : Decimal . from ( 0.125 ) } ,
396
+ { a : Decimal . from ( 0.2 ) , b : 3 , success : true , output : Decimal . from ( 0.008 ) } ,
397
+ { a : Decimal . from ( 0.2 ) , b : 2 , success : true , output : Decimal . from ( 0.04 ) } ,
393
398
{ a : Decimal . from ( 0.2 ) , b : 1 , success : true , output : Decimal . from ( 0.2 ) } ,
394
399
{ a : Decimal . from ( 0.2 ) , b : 0 , success : true , output : Decimal . from ( 1 ) } ,
395
400
{ a : Decimal . from ( 0.2 ) , b : 2 , success : true , output : Decimal . from ( 0.04 ) } ,
396
401
{ a : Decimal . from ( 0.2 ) , b : - 1 , success : true , output : Decimal . from ( 5 ) } ,
397
402
{ a : Decimal . from ( 0.2 ) , b : - 2 , success : true , output : Decimal . from ( 25 ) } ,
403
+ { a : Decimal . from ( 0.2 ) , b : - 3 , success : true , output : Decimal . from ( 125 ) } ,
404
+ { a : Decimal . from ( 3 ) , b : 3 , success : true , output : Decimal . from ( 27 ) } ,
405
+ { a : Decimal . from ( 3 ) , b : 2 , success : true , output : Decimal . from ( 9 ) } ,
398
406
{ a : Decimal . from ( 3 ) , b : 1 , success : true , output : Decimal . from ( 3 ) } ,
399
407
{ a : Decimal . from ( 3 ) , b : 0 , success : true , output : Decimal . from ( 1 ) } ,
400
- { a : Decimal . from ( 3 ) , b : 2 , success : true , output : Decimal . from ( 9 ) } ,
401
408
{ a : Decimal . from ( 3 ) , b : - 1 , success : false } ,
402
409
{ a : Decimal . from ( 3 ) , b : - 2 , success : false } ,
410
+ { a : Decimal . from ( 3 ) , b : - 3 , success : false } ,
403
411
] ;
404
412
for ( const vector of vectors ) {
405
413
const { a, b } = vector ;
406
414
if ( vector . success ) {
407
415
const output = vector . output ;
408
416
const vectors = [ { a, b, output } , { a : a . neg ( ) , b, output : b % 2 == 0 ? output : output . neg ( ) } ] ;
409
417
for ( const { a, b, output } of vectors ) {
410
- assert ( a . pow ( b ) . eq ( output ) ) ;
418
+ assert (
419
+ a . pow ( b ) . eq ( output ) ,
420
+ `a: ${ a . toString ( ) } , b: ${ b } , output: ${ output . toString ( ) } , result: ${ a . pow ( b ) . toString ( ) } ` ,
421
+ ) ;
411
422
}
412
423
} else {
413
424
assert ( wrap ( ( ) => a . pow ( b ) ) instanceof Error ) ;
@@ -576,3 +587,19 @@ Deno.test('lte0', () => {
576
587
assert ( input . lte0 ( ) === output ) ;
577
588
}
578
589
} ) ;
590
+
591
+ Deno . test ( 'e' , ( ) => {
592
+ const vectors = [
593
+ { input : Decimal . from ( 12.3 ) , exponent : 3 , output : Decimal . from ( 12300 ) } ,
594
+ { input : Decimal . from ( 12.3 ) , exponent : 2 , output : Decimal . from ( 1230 ) } ,
595
+ { input : Decimal . from ( 12.3 ) , exponent : 1 , output : Decimal . from ( 123 ) } ,
596
+ { input : Decimal . from ( 12.3 ) , exponent : 0 , output : Decimal . from ( 12.3 ) } ,
597
+ { input : Decimal . from ( 12.3 ) , exponent : - 1 , output : Decimal . from ( 1.23 ) } ,
598
+ { input : Decimal . from ( 12.3 ) , exponent : - 2 , output : Decimal . from ( 0.123 ) } ,
599
+ { input : Decimal . from ( 12.3 ) , exponent : - 3 , output : Decimal . from ( 0.0123 ) } ,
600
+ ] ;
601
+ for ( const { input, exponent, output } of vectors ) {
602
+ assert ( input . e ( exponent ) . eq ( output ) ) ;
603
+ assert ( input . neg ( ) . e ( exponent ) . eq ( output . neg ( ) ) ) ;
604
+ }
605
+ } ) ;
0 commit comments