@@ -12,28 +12,28 @@ sub box($x) { nqp::box_i($x, $bi_type) }
12
12
13
13
my $ one := box(1 );
14
14
15
- my $ b := pir::nqp_bigint_from_str__PPS( $ one , ' -123' );
15
+ my $ b := pir::nqp_bigint_from_str__PSP( ' -123' , $ one );
16
16
my $ c := box(-123 );
17
17
18
18
ok (str ($ b ) eq ' -123' , ' can round-trip negative number (string)' );
19
19
ok (str ($ c ) eq ' -123' , ' can round-trip negative number (string) by boxing' );
20
20
ok (nqp ::unbox_i($ b ) == -123 , ' can round-trip negative number by unboxing' );
21
21
ok (! nqp ::iseq_I($ one , $ b ), ' nqp::iseq_I can return false' );
22
22
ok (nqp ::iseq_I($ one , $ one ), ' nqp::iseq_I can return true' );
23
- ok (iseq(nqp ::mul_I($ b , $ b ), 15129 ,), ' multiplication' );
24
- ok (iseq(nqp ::add_I($ b , $ b ), -246 ,), ' addition' );
25
- ok (nqp ::iseq_I(nqp ::sub_I($ b , $ b ), nqp ::box_i(0 , $ bi_type )), ' subtraction' );
26
- ok (nqp ::iseq_I(nqp ::div_I($ b , $ b ), $ one ), ' division' );
23
+ ok (iseq(nqp ::mul_I($ b , $ b , $ b ), 15129 ,), ' multiplication' );
24
+ ok (iseq(nqp ::add_I($ b , $ b , $ b ), -246 ,), ' addition' );
25
+ ok (nqp ::iseq_I(nqp ::sub_I($ b , $ b , $ b ), nqp ::box_i(0 , $ bi_type )), ' subtraction' );
26
+ ok (nqp ::iseq_I(nqp ::div_I($ b , $ b , $ b ), $ one ), ' division' );
27
27
28
- ok (iseq(nqp ::bitshiftl_I($ one , 3 ), 8 ), ' bitshift left' );
28
+ ok (iseq(nqp ::bitshiftl_I($ one , 3 , $ one ), 8 ), ' bitshift left' );
29
29
ok (iseq($ one , 1 ), ' original not modified by bitshift left' );
30
- ok (iseq(nqp ::bitshiftr_I(box(16 ), 4 ), 1 ), ' bitshift right' );
30
+ ok (iseq(nqp ::bitshiftr_I(box(16 ), 4 , $ one ), 1 ), ' bitshift right' );
31
31
32
- ok (iseq(nqp ::bitand_I(box(0xdead ), box(0xbeef )), 0x9ead ), ' bit and' );
33
- ok (iseq(nqp ::bitor_I( box(0xdead ), box(0xbeef )), 0xfeef ), ' bit or' );
34
- ok (iseq(nqp ::bitxor_I(box(0xdead ), box(0xbeef )), 0x6042 ), ' bit xor' );
32
+ ok (iseq(nqp ::bitand_I(box(0xdead ), box(0xbeef ), $ one ), 0x9ead ), ' bit and' );
33
+ ok (iseq(nqp ::bitor_I( box(0xdead ), box(0xbeef ), $ one ), 0xfeef ), ' bit or' );
34
+ ok (iseq(nqp ::bitxor_I(box(0xdead ), box(0xbeef ), $ one ), 0x6042 ), ' bit xor' );
35
35
36
- ok (iseq(nqp ::bitneg_I(box(-123 )), 122 ), ' bit negation' );
36
+ ok (iseq(nqp ::bitneg_I(box(-123 ), $ one ), 122 ), ' bit negation' );
37
37
38
38
39
39
# Now we'll create a type that boxes a P6bigint.
@@ -46,33 +46,33 @@ $bi_boxer.HOW.compose($bi_boxer);
46
46
# Try some basic operations with it.
47
47
my $ box_val_1 := nqp ::box_i(4 , $ bi_boxer );
48
48
ok (iseq($ box_val_1 , 4 ), ' can box to a complex type with a P6bigint target' );
49
- my $ box_val_2 := pir::nqp_bigint_from_str__PPS( $ bi_boxer , ' 38' );
49
+ my $ box_val_2 := pir::nqp_bigint_from_str__PSP( ' 38' , $ bi_boxer );
50
50
ok (iseq($ box_val_2 , 38 ), ' can get a bigint from a string with boxing type' );
51
- ok (iseq(nqp ::add_I($ box_val_1 , $ box_val_2 ), 42 ), ' addition works on boxing type' );
51
+ ok (iseq(nqp ::add_I($ box_val_1 , $ box_val_2 , $ bi_boxer ), 42 ), ' addition works on boxing type' );
52
52
53
53
54
54
# Note that the last argument to pow_I should be capable of boxing a num,
55
55
# so $bi_type is wrong here. But so far we only test the integer case,
56
56
# so we can get away with it.
57
- my $ big := nqp ::pow_I($ c , box(42 ), $ bi_type );
57
+ my $ big := nqp ::pow_I($ c , box(42 ), $ bi_type , $ bi_type );
58
58
ok (str ($ big ) eq ' 5970554685064519004265641008828923248442340700473500698131071806779372733915289638628729' , ' pow (int, positive)' );
59
- ok (iseq(nqp ::pow_I(box(0 ), $ big , $ bi_type ), 0 ), ' pow 0 ** large_number' );
60
- ok (iseq(nqp ::pow_I($ one , $ big , $ bi_type ), 1 ), ' pow 1 ** large_number' );
59
+ ok (iseq(nqp ::pow_I(box(0 ), $ big , $ bi_type , $ bi_type ), 0 ), ' pow 0 ** large_number' );
60
+ ok (iseq(nqp ::pow_I($ one , $ big , $ bi_type , $ bi_type ), 1 ), ' pow 1 ** large_number' );
61
61
62
62
# test conversion to float
63
63
# try it with 2 ** 100, because that's big enough not to fit into a single
64
64
# int, but can be represented exactly in a double
65
- $ big := nqp ::pow_I(box(2 ), box(100 ), $ bi_type );
65
+ $ big := nqp ::pow_I(box(2 ), box(100 ), $ bi_type , $ bi_type );
66
66
ok (nqp ::iseq_n(nqp ::tonum_I($ big ), nqp ::pow_n(2 , 100 )), ' 2**100 to float' );
67
- $ big := nqp ::pow_I(box(-2 ), box(101 ), $ bi_type );
67
+ $ big := nqp ::pow_I(box(-2 ), box(101 ), $ bi_type , $ bi_type );
68
68
ok (nqp ::iseq_n(nqp ::tonum_I($ big ), nqp ::pow_n(-2 , 101 )), ' (-2)**101 to float' );
69
69
# the mantissa can hold much information accurately, so test that too
70
70
my $ factor := 123456789 ;
71
- $ big := nqp ::mul_I($ big , box($ factor ));
71
+ $ big := nqp ::mul_I($ big , box($ factor ), $ bi_type );
72
72
ok (nqp ::iseq_n(nqp ::tonum_I($ big ), nqp ::mul_n($ factor , nqp ::pow_n(-2 , 101 ))), " $ factor * (-2)**101 to float" );
73
73
74
74
$ big := 1e16 ;
75
- my $ converted := nqp ::tonum_I(nqp ::fromstr_I($ bi_type , ' 10000000000000000' ));
75
+ my $ converted := nqp ::tonum_I(nqp ::fromstr_I(' 10000000000000000' , $ bi_type ));
76
76
ok (nqp ::abs_n($ big - $ converted ) / $ big < 1e-4, 'bigint - > float, 1e16 ');
77
77
78
78
my $ float := 123456789e240 ;
0 commit comments