/
bigint.t
1648 lines (1495 loc) · 34.4 KB
/
bigint.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!./parrot
# Copyright (C) 2001-2010, Parrot Foundation.
=head1 NAME
t/pmc/bigint.t - BigInt PMC
=head1 SYNOPSIS
% prove t/pmc/bigint.t
=head1 DESCRIPTION
Tests the BigInt PMC.
=cut
.sub main :main
.include 'test_more.pir'
.local int num_tests
num_tests = 89
plan(num_tests)
.local int good
good = check_libgmp_good()
if good goto do_tests
skip(num_tests)
goto done
do_tests:
clear()
test_set_pmc()
set_and_get()
addition()
subtraction()
multiplication()
division()
negation()
division_by_zero()
floor_division()
negate_min_integer()
absolute_value()
absolute_min_integer()
overflow_coercion()
pow()
compare()
interface()
boolean()
pi()
is_equal()
get_long()
bugfixes()
done:
.end
.include 'iglobals.pasm'
.include 'fp_equality.pasm'
.include 'errors.pasm'
.sub check_libgmp_good
# check libgmp included in Parrot build
$P0 = getinterp
$P1 = $P0[.IGLOBALS_CONFIG_HASH]
$P2 = $P1['gmp']
$I1 = isnull $P2
if $I1, NoLibGMP
diag('# This Parrot uses GMP')
# check version is >= 4.1.4
$P0 = new ['BigInt']
$S3 = $P0.'version'()
$P1 = split '.', $S3
$S0 = $P1[0]
$I0 = $S0
gt $I0, 4, Config2
lt $I0, 4, OldLibGMP
$S1 = $P1[1]
$I1 = $S1
gt $I1, 1, Config2
lt $I1, 1, OldLibGMP
$S2 = $P1[2]
$I2 = $S2
lt $I2, 4, OldLibGMP
Config2:
diag( 'Suitable GMP version [', $S3, '] available' )
.return(1)
NoLibGMP:
diag( 'No BigInt Lib configured' )
.return(0)
OldLibGMP:
diag( 'Buggy GMP version [', $S3, '] with huge digit multiply - please upgrade' )
.return(0)
.end
.sub clear
$P0 = new ['BigInt']
$P0 = 99999999
null $P0
sweep 1
.end
.sub test_set_pmc
$P0 = new ['BigInt']
$P1 = new ['BigNum']
$P1 = 12345
assign $P0, $P1
is($P0, "12345", "can set_pmc")
.end
.sub set_and_get
$I1 = 1
$P0 = new ['BigInt']
$I0 = 999999
$P0 = $I0
$I2 = $P0
eq $I0, $I2, OK1
$I1 = 0
diag('set_int/get_int 999999 wrong')
OK1:
$P0 = new ['BigInt']
$I0 = 999999
$P0 = $I0
$S0 = get_repr $P0
$I2 = $S0
eq $I0, $I2, OK2
$I1 = 0
diag('set_int/get_str 999999 wrong')
OK2:
$P0 = new ['BigInt']
$P0 = 999999
$N1 = $P0
.fp_eq($N1, 999999.0, OK3)
$I1 = 0
diag('set_int/get_num 999999 wrong')
OK3:
$P0 = -999999
$N1 = $P0
.fp_eq($N1, -999999.0, OK4)
$I1 = 0
diag('set_int/get_num -999999 wrong')
OK4:
$P0 = 2147483646
$N1 = $P0
.fp_eq($N1, 2.147483646e9, OK5)
$I1 = 0
diag('set_int/get_num 2^31-1 wrong')
OK5:
$P0 = -2147483646
$N1 = $P0
.fp_eq($N1, -2.147483646e9, OK6)
$I1 = 0
diag('set_int/get_num 2-2^31 wrong')
OK6:
$P0 = new ['BigInt']
$P0 = 1.23e12
$S0 = $P0
eq $S0, '1230000000000', OK7
$I1 = 0
diag('set_num/get_str 1230000000000')
OK7:
$P0 = new ['BigInt']
$P0 = '1230000000000'
$S0 = $P0
eq $S0, '1230000000000', OK8
$I1 = 0
diag('set_str/get_str 1230000000000')
OK8:
$P0 = new ['BigInt']
$P0 = '12345678987654321'
$S0 = $P0[8]
eq $S0, '536705214244372261', OK9
$I1 = 0
diag('get_string_keyed 12345678987654321')
OK9:
$P0[8] = '536705214244372261'
eq $P0, '12345678987654321', OK10
$I1 = 0
diag('set_string_keyed 536705214244372261')
OK10:
ok($I1, 'set and get combinations')
.end
.sub addition
$I1 = 1
$P0 = new ['BigInt']
$P0 = 999999
$P1 = new ['BigInt']
$P1 = 1000000
$P2 = new ['BigInt']
$P2 = add $P0, $P1
$S0 = $P2
eq $S0, '1999999', OK1
$I1 = 0
diag('add 999999+1000000 wrong')
OK1:
$P0 = '12345678987654321'
$P1 = '10000000000000000'
$P2 = add $P1, $P0
$S0 = $P2
eq $S0,'22345678987654321',OK2
$I1 = 0
diag('add 12345678987654321+10000000000000000 wrong')
OK2:
ok($I1, 'add(bigint,bigint)')
$I1 = 1
$P0 = 999999
$P2 = add $P0, 1000000
$S0 = $P2
eq $S0,'1999999',OK3
$I1 = 0
diag('add 999999+1000000 wrong')
OK3:
$P0 = '100000000000000000000'
$P2 = add $P0, 1000000
$S0 = $P2
eq $S0,'100000000000001000000',OK4
$I1 = 0
diag('add 100000000000000000000+1000000 wrong')
OK4:
ok($I1, 'add(bigint,nativeint)')
$I1 = 1
$P0 = '12345678987654321'
$I0 = 12345
$P2 = add $P0, $I0
eq $P2, '12345678987666666', OK5
$I1 = 0
diag('add 12345678987654321+12345 wrong')
OK5:
ok($I1, 'add(bigint,integer)')
$P0 = new ['BigInt']
$P0 = '12345678900000000'
$P1 = new ['BigInt']
$P1 = '87654321'
$P2 = new ['BigInt']
$P2 = '12345678987654321'
add $P0, $P1
eq $P0, $P2, OK6
$I1 = 0
diag('add 12345678900000000+87654321 wrong')
OK6:
ok($I1, 'i_add(bigint,bigint)')
$P0 = '12345678900000000'
add $P0, 87654321
eq $P0, $P2, OK7
$I1 = 0
diag('add 12345678900000000+87654321 for nativeint wrong')
OK7:
ok($I1, 'i_add(bigint,nativeint)')
$P0 = '12345678900000000'
$P1 = new ['Integer']
$P1 = 87654321
add $P0, $P1
eq $P0, $P2, OK8
$I1 = 0
diag('add 12345678900000000+87654321 for integer wrong')
OK8:
ok($I1, 'i_add(bigint,integer)')
$P0 = '12345678900000000'
$P1 = new ['Float']
$P1 = 1.1
push_eh E1
add $P0, $P0, $P1
$I1 = 0
diag('Failed to throw exception')
E1:
pop_eh
get_results '0', $P5
$S0 = $P5
eq $S0, "BigInt: no multiple dispatch variant 'add' for Float", OK9
$I1 = 0
$S0 = concat $S0, ' is wrong exception type'
diag($S0)
OK9:
ok($I1, 'add(bigint,float) throws exception')
$I1 = 1
push_eh E2
add $P0, 1.1
$I1 = 0
diag('Failed to throw exception')
E2:
pop_eh
get_results '0', $P5
$S0 = $P5
eq $S0, "BigInt: no multiple dispatch variant 'i_add_float' for FLOATVAL", OK10
$I1 = 0
$S0 = concat $S0, ' is wrong exception type'
diag($S0)
OK10:
ok($I1, 'i_add(bigint,float) throws exception')
$I1 = 1
$P1 = new ['String']
$P1 = "eheh"
push_eh E3
add $P0, $P1
$I1 = 0
diag('Failed to throw exception')
E3:
pop_eh
get_results '0', $P5
$S0 = $P5
eq $S0, "BigInt: no multiple dispatch variant 'i_add' for String", OK11
$I1 = 0
$S0 = concat $S0, ' is wrong exception type'
diag($S0)
OK11:
ok($I1, "i_add(bigint,string) throws exception")
.end
.sub subtraction
$I1 = 1
$P0 = new ['BigInt']
$P0 = '12345678'
$P1 = new ['BigInt']
$P1 = '5678'
$P2 = new ['BigInt']
$P2 = sub $P0, $P1
$I0 = $P2
eq $I0, 12340000, OK1
$I1 = 0
diag('sub 12345678-5678 wrong')
OK1:
$P0 = '123456789012345678'
$P2 = sub $P0, $P1
$P3 = new ['BigInt']
$P3 = '123456789012340000'
eq $P2, $P3, OK2
$I1 = 0
diag('sub 123456789012345678-5678 wrong')
OK2:
$P1 = '223456789012345678'
$P2 = sub $P0, $P1
$P3 = '-100000000000000000'
eq $P2, $P3, OK3
$I1 = 0
diag('sub 123456789012345678-(-100000000000000000) wrong')
OK3:
ok($I1, 'sub(bigint,bigint)')
$I1 = 1
$P0 = 12345678
$P2 = sub $P0, 5678
$I0 = $P2
eq $I0, 12340000, OK4
$I1 = 0
diag('sub 12345678-5678 wrong')
OK4:
$P0 = '123456789012345678'
$P2 = sub $P0, 5678
$P3 = new ['BigInt']
$P3 = '123456789012340000'
eq $P2, $P3, OK5
$I1 = 0
diag('sub 123456789012345678-5678 wrong')
OK5:
$P0 = new ['BigInt']
$P0 = 12345678
$P1 = new ['Integer']
$P1 = 5678
$P2 = new ['BigInt']
$P2 = sub $P0, $P1
$I0 = $P2
eq $I0, 12340000, OK6
$I1 = 0
diag('sub 12345678-5678 wrong')
OK6:
$P0 = '123456789012345678'
$P2 = sub $P0, $P1
$P3 = new ['BigInt']
$P3 = '123456789012340000'
eq $P2, $P3, OK7
$I1 = 0
diag('sub 123456789012345678-5678 wrong')
OK7:
$P0 = 9876543
$P4 = new ['Integer']
$P4 = 44
$P2 = sub $P0, $P4
$I0 = $P2
eq $I0, 9876499, OK8
$I1 = 0
diag('sub 9876543-44 wrong')
OK8:
$P0 = '9876543219876543'
$P2 = sub $P0, $P4
$P3 = '9876543219876499'
eq $P3, $P2, OK9
$I1 = 0
diag('sub 9876543219876543-44 wrong')
OK9:
ok($I1, 'sub(bigint,integer)')
$P0 = new ['BigInt']
$P0 = '12345678987654321'
$P1 = new ['BigInt']
$P1 = '123456789'
$P2 = new ['BigInt']
$P2 = '12345678864197532'
sub $P0, $P1
eq $P0, $P2, OK11
$I1 = 0
diag('i_sub 12345678987654321-123456789 is wrong')
OK10:
ok($I1, 'i_sub(bigint,bigint)')
$P0 = '12345678987654321'
sub $P0, 123456789
eq $P0, $P2, OK11
$I1 = 0
diag('i_sub 12345678987654321-123456789 with nativeint is wrong')
OK11:
ok($I1, 'i_sub(bigint,nativeint)')
$P0 = '12345678987654321'
$P1 = new ['Integer']
$P1 = 123456789
sub $P0, $P1
eq $P0, $P2, OK12
$I1 = 0
diag('i_sub 12345678987654321-123456789 with integer is wrong')
OK12:
ok($I1, 'i_sub(bigint,integer)')
$P0 = '11111111111111111'
dec $P0
eq $P0, 11111111111111110, OK13
$I1 = 0
diag('decrement is wrong')
OK13:
ok($I1, 'decrement')
push_eh E1
sub $P0, 1.1
E1:
pop_eh
.get_results($P2)
is($P2, "BigInt: no multiple dispatch variant 'i_subtract_float' for FLOATVAL", "i_sub(bigint,float) throws exception")
$P1 = new ['String']
$P1 = "sdagsdg"
push_eh E2
sub $P0, $P1
E2:
pop_eh
.get_results($P2)
is($P2, "BigInt: no multiple dispatch variant 'i_subtract' for String", "i_sub(bigint,string) throws exception")
$P1 = new ['Float']
$P1 = 1.1
push_eh E3
sub $P0, $P0, $P1
E3:
pop_eh
.get_results($P2)
is($P2, "BigInt: no multiple dispatch variant 'subtract' for Float", "sub(bigint,float) throws exception")
$P1 = new ['String']
$P1 = "sdagsdg"
push_eh E4
sub $P0, $P0, $P1
E4:
pop_eh
.get_results($P2)
is($P2, "BigInt: no multiple dispatch variant 'subtract' for String", "sub(bigint,string) throws exception")
.end
.sub multiplication
$P0 = new ['BigInt']
$P0 = 999999
$P1 = new ['BigInt']
$P1 = 1000000
$P2 = new ['BigInt']
$P2 = mul $P0, $P1
$S0 = $P2
is($S0, '999999000000', 'mul(bigint,bigint)')
$P0 = new ['BigInt']
$P0 = 999999
$P2 = new ['BigInt']
$P2 = mul $P0, 1000000
is($P2, '999999000000', 'mul(bigint,nativeint)')
$P0 = new ['BigInt']
$P0 = '999999'
$P1 = new ['Integer']
$P1 = 1000000
$P2 = new ['BigInt']
$P2 = mul $P0, $P1
$S0 = $P2
is($S0, '999999000000', 'mul(bigint,integer)')
$P1 = new ['BigInt']
$P1 = 1000000
mul $P0, $P1
is($P0, '999999000000', 'i_mul(bigint,bigint)')
$P0 = 999999
mul $P0, 1000000
is($P0, '999999000000', 'i_mul(bigint,nativeint)')
$P0 = 999999
$P1 = new ['Integer']
$P1 = 1000000
mul $P0, $P1
is($P0, '999999000000', 'i_mul(bigint,integer)')
$I1 = 1
$P0 = '12345678900000000'
$P1 = new ['Float']
$P1 = 1.1
push_eh E1
mul $P0, $P0, $P1
$I1 = 0
diag('Failed to throw exception')
E1:
pop_eh
get_results '0', $P5
$S0 = $P5
eq $S0, "BigInt: no multiple dispatch variant 'multiply' for Float", OK1
$I1 = 0
$S0 = concat $S0, ' is wrong exception type'
diag($S0)
OK1:
ok($I1, 'multiply(bigint,float) throws exception')
$I1 = 1
push_eh E2
mul $P0, 0.1
$I1 = 0
diag('Failed to throw exception')
E2:
pop_eh
get_results '0', $P5
$S0 = $P5
eq $S0, "BigInt: no multiple dispatch variant 'i_multiply_float' for FLOATVAL", OK2
$I1 = 0
$S0 = concat $S0, ' is wrong exception type'
diag($S0)
OK2:
ok($I1, 'i_multiply(bigint,float) throws exception')
$I1 = 1
$P1 = new ['Float']
$P1 = 1.1
push_eh E3
mul $P0, $P1
E3:
pop_eh
.get_results($P2)
is($P2, "BigInt: no multiple dispatch variant 'i_multiply' for Float", "i_mul(bigint,float) throws exception")
$P1 = new ['String']
$P1 = "sdagsdg"
push_eh E4
mul $P0, $P1
E4:
pop_eh
.get_results($P2)
is($P2, "BigInt: no multiple dispatch variant 'i_multiply' for String", "i_mul(bigint,string) throws exception")
.end
.sub division
$I1 = 1
$P0 = new ['BigInt']
$P0 = '100000000000000000000'
$P1 = new ['BigInt']
$P1 = '100000000000000000000'
$P2 = new ['BigInt']
$P2 = div $P0, $P1
$I0 = $P2
eq $I0, 1, OK1
$I1 = 0
diag('div 100000000000000000000/100000000000000000000 wrong')
OK1:
$P3 = new ['BigInt']
$P3 = '10000000000000'
$P1 = 10000000
$P2 = div $P0, $P1
eq $P2, $P3, OK2
$I1 = 0
diag('div 100000000000000000000/10000000 wrong')
OK2:
$P1 = 10
$P3 = '10000000000000000000'
$P2 = div $P0, $P1
eq $P2, $P3, OK3
$I1 = 0
diag('div 100000000000000000000/10 wrong')
OK3:
$P1 = -1
$P3 = '-100000000000000000000'
$P2 = div $P0, $P1
eq $P2, $P3, OK4
$I1 = 0
diag('div 100000000000000000000/(-1) wrong')
OK4:
ok($I1, 'div(bigint,bigint)')
$I1 = 1
$P0 = new ['BigInt']
$P0 = '100000000000000000000'
$P1 = new ['BigInt']
$P1 = div $P0, 10
$P2 = new ['BigInt']
$P2 = '10000000000000000000'
eq $P1, $P2, OK5
$I1 = 0
diag('div 100000000000000000000/10 wrong')
OK5:
$P0 = '100000000000000'
$P1 = div $P0, 10000000
$P2 = 10000000
eq $P1, $P2, OK6
$I1 = 0
diag('div 100000000000000/10000000 wrong')
OK6:
ok($I1, 'div(bigint,nativeint)')
$I1 = 1
$P0 = new ['BigInt']
$P0 = '100000000000000000000'
$P1 = new ['BigInt']
$P3 = new ['Integer']
$P3 = 10
$P1 = div $P0, $P3
$P2 = new ['BigInt']
$P2 = '10000000000000000000'
eq $P1, $P2, OK7
$I1 = 0
diag('div 100000000000000000000/10 wrong')
OK7:
$P0 = '100000000000000'
$I0 = 10000000
$P1 = div $P0, $I0
$P2 = 10000000
eq $P1, $P2, OK8
$I1 = 0
diag('div 100000000000000/10000000 wrong')
OK8:
ok($I1, 'div(bigint,integer)')
$I1 = 1
$P0 = '100000000000000'
$I0 = -10000000
$P1 = div $P0, $I0
$P2 = -10000000
eq $P1, $P2, OK9
$I1 = 0
diag('div 10000000000000/-10000000 wrong')
OK9:
ok($I1, 'div(bigint,-integer)')
$I1 = 1
$P1 = new ['BigInt']
$P1 = 10000000
div $P0, $P1
eq $P0, 10000000, OK10
$I1 = 0
diag('div 10000000000000/10000000 wrong')
OK10:
ok($I1, 'i_div(bigint,bigint)')
$I1 = 1
$P0 = 100000000000000
div $P0, 10000000
eq $P0, 10000000, OK11
$I1 = 0
diag('div 10000000000000/10000000 with nativeint wrong')
OK11:
ok($I1, 'i_div(bigint,nativeint)')
$I1 = 1
$P0 = 100000000000000
$P1 = new ['Integer']
$P1 = 10000000
div $P0, $P1
eq $P0, 10000000, OK12
$I1 = 0
diag('div 10000000000000/10000000 with integer wrong')
OK12:
ok($I1, 'i_div(bigint,integer)')
$I1 = 1
$P0 = new ['BigInt']
$P0 = '12345678987654321'
$P1 = new ['BigInt']
$P2 = '50'
$P1 = mod $P0, $P2
eq $P1, 21, OK13
$I1 = 0
diag('mod 12345678987654321%50 wrong')
OK13:
ok($I1, 'mod(bigint,integer)')
$I1 = 1
$P2 = -50
$P1 = mod $P0, $P2
eq $P1, 21, OK14
$I1 = 0
diag('mod 12345678987654321%-50 wrong')
OK14:
ok($I1, 'mod(bigint,-integer)')
$I1 = 1
$P0 = '12345678987654321'
$P1 = new ['BigInt']
$P1 = '50'
mod $P0, $P1
eq $P0, 21, OK15
$I1 = 0
diag('mod 12345678987654321%50 wrong')
OK15:
ok($I1, 'i_mod(bigint,bigint)')
$I1 = 1
$P0 = '12345678987654321'
$P1 = new ['Integer']
$P1 = 50
mod $P0, $P1
eq $P0, 21, OK16
$I1 = 0
diag('mod 12345678987654321%50 with integer wrong')
OK16:
ok($I1, 'i_mod(bigint,integer)')
$I1 = 1
$P2 = new ['String']
push_eh E1
$P1 = mod $P0, $P2
$I1 = 0
diag('Failed to throw exception')
E1:
pop_eh
get_results '0', $S0
eq $S0, "BigInt: no multiple dispatch variant 'modulus' for String", OK17
$I1 = 0
$S0 = concat $S0,' is wrong exception type'
diag($S0)
OK17:
ok($I1, 'mod(bigint,string) throws exception')
$I1 = 1
push_eh E2
mod $P0, $P2
$I1 = 0
diag('Failed to throw exception')
E2:
pop_eh
get_results '0', $S0
eq $S0, "BigInt: no multiple dispatch variant 'i_modulus' for String", OK18
$I1 = 0
$S0 = concat $S0,' is wrong exception type'
diag($S0)
OK18:
ok($I1, 'i_mod(bigint,string) throws exception')
$P1 = new ['Float']
$P1 = 1.1
push_eh E3
div $P0, $P1
E3:
pop_eh
.get_results($P2)
is($P2, "BigInt: no multiple dispatch variant 'i_divide' for Float", "i_div(bigint,float) throws exception")
$P1 = new ['String']
$P1 = "sdagsdg"
push_eh E4
div $P0, $P1
E4:
pop_eh
.get_results($P2)
is($P2, "BigInt: no multiple dispatch variant 'i_divide' for String", "i_div(bigint,string) throws exception")
$P1 = new ['String']
$P1 = "sdagsdg"
push_eh E5
div $P0, $P0, $P1
E5:
pop_eh
.get_results($P2)
is($P2, "BigInt: no multiple dispatch variant 'divide' for String", "div(bigint,string) throws exception")
.end
.sub division_by_zero
$I1 = 1
$P0 = new ['BigInt']
$P0 = '1000000000000000000000'
$P1 = new ['BigInt']
## divide by a zero BigInt
$P2 = new ['BigInt']
$P2 = 0
push_eh E1
$P1 = div $P0, $P2
$I1 = 0
diag('Failed to throw exception')
E1:
pop_eh
get_results '0', $P0
$S0 = $P0
eq $S0, 'Divide by zero', OK1
$I1 = 0
$S0 = concat $S0, ' is wrong exception type'
diag($S0)
OK1:
ok($I1, 'div(bigint,bigint 0) throws "Divide by zero" exception')
$I1 = 1
$P0 = new ['BigInt']
$P0 = '1000000000000000000000'
$P1 = new ['BigInt']
## modulus by a zero BigInt
$P2 = new ['BigInt']
$P2 = 0
push_eh E2
$P1 = mod $P0, $P2
$I1 = 0
diag('Failed to throw exception')
E2:
pop_eh
get_results '0', $P0
$S0 = $P0
eq $S0, 'Divide by zero', OK2
$I1 = 0
$S0 = concat $S0, ' is wrong exception type'
diag($S0)
OK2:
ok($I1, 'mod(bigint,bigint 0) throws "Divide by zero" exception')
$I1 = 1
$P0 = new ['BigInt']
$P0 = '1000000000000000000000'
$P1 = new ['BigInt']
## divide by a zero Integer
$P2 = new ['Integer']
$P2 = 0
push_eh E3
$P1 = div $P0, $P2
$I1 = 0
diag('Failed to throw exception')
E3:
pop_eh
get_results '0', $P0
$S0 = $P0
eq $S0, 'Divide by zero', OK3
$I1 = 0
$S0 = concat $S0, ' is wrong exception type'
diag($S0)
OK3:
ok($I1, 'div(bigint,integer 0) throws "Divide by zero" exception')
$I1 = 1
$P0 = new ['BigInt']
$P0 = '1000000000000000000000'
$P1 = new ['BigInt']
## modulus by a zero Integer
$P2 = new ['Integer']
$P2 = 0
push_eh E4
$P1 = mod $P0, $P2
$I1 = 0
diag('Failed to throw exception')
E4:
pop_eh
get_results '0', $S0
eq $S0, 'Divide by zero', OK4
$I1 = 0
$S0 = concat $S0, ' is wrong exception type'
diag($S0)
OK4:
ok($I1, 'mod(bigint,integer 0) throws "Divide by zero" exception')
$I1 = 1
.end
.sub floor_division
$I1 = 1
$P0 = new ['BigInt']
$P1 = new ['BigInt']
$P2 = new ['BigInt']
$P0 = '12345678987654321'
$P1 = '987654321'
$P2 = fdiv $P0, $P1
eq $P2, 12499999, OK1
$I1 = 0
diag('fdiv 12345678987654321/987654321 is wrong')
OK1:
ok($I1, 'fdiv(bigint,bigint)')
$I1 = 1
$P2 = fdiv $P0, 123456789
eq $P2, 100000000, OK2
$I1 = 0
diag('fdiv 12345678987654321/123456789 is wrong')
OK2:
ok($I1, 'fdiv(bigint,nativeint)')
$I1 = 1
$P1 = new ['Integer']
$P1 = 123456789
$P2 = fdiv $P0, $P1
eq $P2, 100000000, OK3
$I1 = 0
diag('fdiv 12345678987654321/int 123456789 is wrong')
OK3:
ok($I1, 'fdiv(bigint,integer)')
$I1 = 1
$P0 = '12345678987654321'
$P1 = new ['BigInt']
$P1 = '987654321'
fdiv $P0, $P1
eq $P0, 12499999, OK4
$I1 = 0
diag('fdiv 12345678987654321/987654321 is wrong')
OK4:
ok($I1, 'i_fdiv(bigint,bigint)')
$I1 = 1
$P0 = '12345678987654321'
fdiv $P0, 987654321
eq $P0, 12499999, OK5
$I1 = 0
diag('fdiv 12345678987654321/987654321 with nativeint is wrong')
OK5:
ok($I1, 'i_fdiv(bigint,nativeint)')
$I1 = 1
$P0 = '12345678987654321'
$P1 = new ['Integer']
$P1 = 987654321
fdiv $P0, $P1
eq $P0, 12499999, OK6
$I1 = 0
diag('fdiv 12345678987654321/987654321 with integer is wrong')
OK6:
ok($I1, 'i_fdiv(bigint,integer)')
$I1 = 1
$P1 = new ['Float']
$P1 = 1.1
push_eh E1
fdiv $P0, $P0, $P1
E1:
.get_results($P2)
pop_eh
is($P2, "BigInt: no multiple dispatch variant 'floor_divide' for Float", "fdiv(bigint,float) throws exception")
$P1 = new ['Float']
$P1 = 1.1
push_eh E2
fdiv $P0, $P1
E2:
.get_results($P2)
pop_eh
is($P2, "BigInt: no multiple dispatch variant 'i_floor_divide' for Float", "i_fdiv(bigint,float) throws exception")
$P0 = new ['BigInt']
$P0 = '1234'
$P1 = new ['BigInt']
$P1 = '-32'