@@ -89,7 +89,6 @@ R(["pyret-base/js/js-numbers"], function(JN) {
8989 var bigIntStr = "1" + new Array ( 309 + 1 ) . join ( "0" ) ; // 1 followed by 309 0s
9090 expect ( JN . fromString ( bigIntStr , sampleErrbacks ) ) . toEqual ( JN . makeBignum ( bigIntStr ) ) ;
9191
92-
9392 // for sci-not and 'p/q', fromString() and makeBignum()/makeRational() can give
9493 // structurally unequal but operationally equivalent results, so the following fails:
9594 // expect(JN.fromString("1e141", sampleErrbacks)).toEqual(JN.makeBignum("1e141"));
@@ -290,7 +289,7 @@ R(["pyret-base/js/js-numbers"], function(JN) {
290289 JN . toFixnum ( Infinity ) ,
291290 0.00001 , sampleErrbacks ) ;
292291 } )
293- . toThrowError ( / d o m a i n E r r o r / ) ;
292+ . toThrowError ( / o v e r f l o w / ) ;
294293
295294 } ) ;
296295
@@ -344,6 +343,64 @@ R(["pyret-base/js/js-numbers"], function(JN) {
344343
345344 } ) ;
346345
346+ it ( "nthRoot integerNthRoot" , function ( ) {
347+ expect ( JN . equals (
348+ JN . _innards . nthRoot ( 3 , 8 , sampleErrbacks ) ,
349+ Math . pow ( 8 , 1 / 3 ) ,
350+ sampleErrbacks ) )
351+ . toBe ( true ) ;
352+ expect ( JN . roughlyEquals (
353+ JN . _innards . nthRoot ( 3 , 7.5 , sampleErrbacks ) ,
354+ Math . pow ( 7.5 , 1 / 3 ) ,
355+ 0.00001 , sampleErrbacks ) )
356+ . toBe ( true ) ;
357+ expect ( JN . roughlyEquals (
358+ JN . _innards . nthRoot ( 3 , 8.5 , sampleErrbacks ) ,
359+ Math . pow ( 8.5 , 1 / 3 ) ,
360+ 0.00001 , sampleErrbacks ) )
361+ . toBe ( true ) ;
362+ expect ( JN . equals (
363+ JN . _innards . nthRoot ( 3 , - 8 , sampleErrbacks ) ,
364+ - Math . pow ( 8 , 1 / 3 ) ,
365+ sampleErrbacks ) )
366+ . toBe ( true ) ;
367+ expect ( JN . roughlyEquals (
368+ JN . _innards . nthRoot ( 3 , - 7.5 , sampleErrbacks ) ,
369+ - Math . pow ( 7.5 , 1 / 3 ) ,
370+ 0.00001 , sampleErrbacks ) )
371+ . toBe ( true ) ;
372+ expect ( JN . roughlyEquals (
373+ JN . _innards . nthRoot ( 3 , - 8.5 , sampleErrbacks ) ,
374+ - Math . pow ( 8.5 , 1 / 3 ) ,
375+ 0.00001 , sampleErrbacks ) )
376+ . toBe ( true ) ;
377+ expect ( function ( ) {
378+ JN . _innards . nthRoot ( - 3 , 8 , sampleErrbacks ) ;
379+ } )
380+ . toThrowError ( / r o o t .* n e g a t i v e / ) ;
381+
382+ expect ( JN . equals (
383+ JN . _innards . integerNthRoot ( 3 , 8 , sampleErrbacks ) ,
384+ 2 , sampleErrbacks ) )
385+ . toBe ( true ) ;
386+ expect ( JN . equals (
387+ JN . _innards . integerNthRoot ( 3 , 7.5 , sampleErrbacks ) ,
388+ 1 , sampleErrbacks ) )
389+ . toBe ( true ) ;
390+ expect ( JN . equals (
391+ JN . _innards . integerNthRoot ( 3 , 8.5 , sampleErrbacks ) ,
392+ 2 , sampleErrbacks ) )
393+ . toBe ( true ) ;
394+ expect ( function ( ) {
395+ JN . _innards . integerNthRoot ( 3 , - 8 , sampleErrbacks ) ;
396+ } )
397+ . toThrowError ( / r a d i c a n d .* n e g a t i v e / ) ;
398+ expect ( function ( ) {
399+ JN . _innards . integerNthRoot ( - 3 , 8 , sampleErrbacks ) ;
400+ } )
401+ . toThrowError ( / r o o t .* n e g a t i v e / ) ;
402+
403+ } ) ;
347404
348405 it ( "BigInteger methods" , function ( ) {
349406
@@ -356,13 +413,13 @@ R(["pyret-base/js/js-numbers"], function(JN) {
356413 // shd raise exception for arg outside [-1, +1]
357414 // but this is not testable via Pyret, because args are always sane
358415 // by the time this method is called
359- expect ( function ( ) { JN . makeBignum ( - 1.5 ) . asin ( sampleErrbacks ) ; } ) . toThrowError ( / d o m a i n E r r o r / ) ;
360- expect ( function ( ) { JN . makeBignum ( + 1.5 ) . asin ( sampleErrbacks ) ; } ) . toThrowError ( / d o m a i n E r r o r / ) ;
416+ expect ( function ( ) { JN . makeBignum ( - 1.5 ) . asin ( sampleErrbacks ) ; } ) . toThrowError ( / o u t o f d o m a i n / ) ;
417+ expect ( function ( ) { JN . makeBignum ( + 1.5 ) . asin ( sampleErrbacks ) ; } ) . toThrowError ( / o u t o f d o m a i n / ) ;
361418
362419 // BigInteger.*acos
363420 // shd raise exc for arg < -1 or > 1
364- expect ( function ( ) { JN . makeBignum ( - 1.5 ) . acos ( sampleErrbacks ) ; } ) . toThrowError ( / d o m a i n E r r o r / ) ;
365- expect ( function ( ) { JN . makeBignum ( + 1.5 ) . acos ( sampleErrbacks ) ; } ) . toThrowError ( / d o m a i n E r r o r / ) ;
421+ expect ( function ( ) { JN . makeBignum ( - 1.5 ) . acos ( sampleErrbacks ) ; } ) . toThrowError ( / o u t o f d o m a i n / ) ;
422+ expect ( function ( ) { JN . makeBignum ( + 1.5 ) . acos ( sampleErrbacks ) ; } ) . toThrowError ( / o u t o f d o m a i n / ) ;
366423
367424 // BigInteger.*.atan
368425 // should work
@@ -371,7 +428,7 @@ R(["pyret-base/js/js-numbers"], function(JN) {
371428 // atan2 (perhaps Pyret test is enough)
372429 expect ( function ( ) {
373430 JN . atan2 ( JN . makeBignum ( 0 ) , JN . makeBignum ( 0 ) , sampleErrbacks ) ;
374- } ) . toThrowError ( / d o m a i n E r r o r / ) ;
431+ } ) . toThrowError ( / o u t o f d o m a i n / ) ;
375432
376433 // BigInteger.*.sin
377434 // should work
@@ -385,12 +442,11 @@ R(["pyret-base/js/js-numbers"], function(JN) {
385442 // should work
386443 expect ( JN . makeBignum ( 0 ) . tan ( sampleErrbacks ) ) . toEqual ( 0 ) ;
387444
388-
389445 // BigInteger.*.expt calls bnPow, which calls bnpExp
390446 // should raise exception for too-large
391447 expect ( function ( ) {
392448 JN . makeBignum ( 2 ) . expt ( JN . makeBignum ( 0xffffffff + 1 ) , sampleErrbacks ) ;
393- } ) . toThrowError ( / d o m a i n E r r o r / ) ;
449+ } ) . toThrowError ( / e x p o n e n t . * t o o l a r g e / ) ;
394450
395451 // BigInteger.*.log
396452 // should raise exception for arg <= 0
@@ -721,7 +777,6 @@ R(["pyret-base/js/js-numbers"], function(JN) {
721777
722778 } ) ;
723779
724-
725780 } ) ;
726781
727782 jazz . execute ( ) ;
0 commit comments