@@ -181,6 +181,44 @@ generatePrime(
181181 }
182182}
183183
184+ {
185+ // This is impossible because it implies (prime % 2**64) == 1 and
186+ // prime < 2**64, meaning prime = 1, but 1 is not prime.
187+ for ( const add of [ 2n ** 64n , 2n ** 65n ] ) {
188+ assert . throws ( ( ) => {
189+ generatePrimeSync ( 64 , { add } ) ;
190+ } , {
191+ code : 'ERR_OUT_OF_RANGE' ,
192+ message : 'invalid options.add'
193+ } ) ;
194+ }
195+
196+ // Any parameters with rem >= add lead to an impossible condition.
197+ for ( const rem of [ 7n , 8n , 3000n ] ) {
198+ assert . throws ( ( ) => {
199+ generatePrimeSync ( 64 , { add : 7n , rem } ) ;
200+ } , {
201+ code : 'ERR_OUT_OF_RANGE' ,
202+ message : 'invalid options.rem'
203+ } ) ;
204+ }
205+
206+ // This is possible, but not allowed. It implies prime == 7, which means that
<
5CC0
td data-grid-cell-id="diff-5c3a1fda383883b52618603cdcbe6abb4bac9fdcfdc48e6bbae73bc4ce02fa66-183-207-0" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionNum-bgColor, var(--diffBlob-addition-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">207+ // we did not actually generate a random prime.
208+ assert . throws ( ( ) => {
209+ generatePrimeSync ( 3 , { add : 8n , rem : 7n } ) ;
210+ } , {
211+ code : 'ERR_OUT_OF_RANGE'
212+ } ) ;
213+
214+ // This is possible and allowed (but makes little sense).
215+ assert . strictEqual ( generatePrimeSync ( 4 , {
216+ add : 15n ,
217+ rem : 13n ,
218+ bigint : true
219+ } ) , 13n ) ;
220+ }
221+
184222
4675
[ 1 , 'hello' , { } , [ ] ] . forEach ( ( i ) => {
185223 assert . throws ( ( ) => checkPrime ( i ) , {
186224 code : 'ERR_INVALID_ARG_TYPE'
0 commit comments