-
Notifications
You must be signed in to change notification settings - Fork 1
/
readable_integer_x.e
executable file
·1741 lines (1560 loc) · 39.8 KB
/
readable_integer_x.e
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
note
description: "Functionality to query the status of an arbitrary precision integer"
author: "Colin LeMahieu"
date: "$Date$"
revision: "$Revision$"
quote: "The urge to save humanity is almost always a false front for the urge to rule. - H.L. Mencken"
deferred class
READABLE_INTEGER_X
inherit
ANY
undefine
default_create,
is_equal,
copy
redefine
out
select
out
end
DEBUG_OUTPUT
undefine
default_create,
is_equal,
copy,
out
redefine
debug_output
end
NUMERIC
rename
plus as plus_value alias "+",
minus as minus_value alias "-",
product as product_value alias "*",
quotient as quotient_value alias "/",
opposite as opposite_value alias "-"
undefine
default_create,
out
redefine
copy,
is_equal
end
COMPARABLE
undefine
default_create,
out
redefine
copy,
is_equal,
three_way_comparison
end
INTEGER_X_ASSIGNMENT
rename
add as add_special,
sub as sub_special,
mul as mul_special,
bit_xor_lshift as bit_xor_lshift_special,
bit_xor as bit_xor_special
export
{NONE}
all
undefine
default_create,
is_equal,
copy,
out
end
INTEGER_X_ACCESS
rename
add as add_special,
sub as sub_special,
mul as mul_special,
cmp as cmp_special,
tdiv_qr as tdiv_qr_special,
sizeinbase as sizeinbase_special,
bit_xor_lshift as bit_xor_lshift_special,
bit_xor as bit_xor_special
export
{NONE}
all
undefine
default_create,
is_equal,
copy,
out
end
INTEGER_X_ARITHMETIC
rename
abs as abs_integer_x,
cmp as cmp_special,
bit_xor_lshift as bit_xor_lshift_special,
bit_xor as bit_xor_special
export
{NONE}
all
undefine
default_create,
is_equal,
copy,
out
end
INTEGER_X_COMPARISON
export
{NONE}
all
undefine
default_create,
is_equal,
copy,
out
end
INTEGER_X_LOGIC
rename
add as add_special,
sub as sub_special,
mul as mul_special,
bit_and as bit_and_integer_x,
bit_complement as bit_complement_integer_x,
bit_or as bit_or_integer_x,
bit_test as bit_test_integer_x,
bit_xor as bit_xor_integer_x,
bit_xor_lshift as bit_xor_lshift_integer_x
export
{NONE}
all
undefine
default_create,
is_equal,
copy,
out
end
INTEGER_X_IO
rename
sizeinbase as sizeinbase_special
export
{NONE}
all
undefine
default_create,
is_equal,
copy,
out
end
INTEGER_X_RANDOM
rename
add as add_special,
sub as sub_special,
mul as mul_special,
cmp as cmp_special,
bit_xor_lshift as bit_xor_lshift_special,
bit_xor as bit_xor_special
export
{NONE}
all
undefine
default_create,
is_equal,
copy,
out
end
INTEGER_X_SIZING
export
{NONE}
all
undefine
default_create,
is_equal,
copy,
out
end
INTEGER_X_NUMBER_THEORY
rename
abs as abs_integer_x,
mod as mod_integer_x,
gcd as gcd_integer_x,
bit_and as bit_and_integer_x,
bit_complement as bit_complement_integer_x,
bit_or as bit_or_integer_x,
bit_test as bit_test_integer_x,
bit_xor as bit_xor_integer_x,
powm as powm_integer_x,
bit_xor_lshift as bit_xor_lshift_integer_x,
invert_gf as invert_gf_integer_x
export
{NONE}
all
undefine
default_create,
is_equal,
copy,
out
end
INTEGER_X_DIVISION
rename
abs as abs_integer_x,
cmp as cmp_special,
mod as mod_integer_x,
bit_xor_lshift as bit_xor_lshift_special,
bit_xor as bit_xor_special
export
{NONE}
all
undefine
default_create,
is_equal,
copy,
out
end
SPECIAL_UTILITY
export
{INTEGER_X_FACILITIES}
all
undefine
default_create,
is_equal,
copy,
out
end
feature {NONE} -- Initialization
default_create
-- Initialize `Current' to zero
do
create item.make_filled (0, 1)
count := 0
ensure then
zero: is_zero
end
make_set (other: READABLE_INTEGER_X)
-- Initialize `Current' to be a copy of `other'
do
create item.make_filled (0, 0)
set_from_other (other)
ensure
equal: Current ~ other
end
make_from_integer (i: INTEGER)
-- Initialize `Current' from `i'.
do
default_create
set_from_integer (i)
ensure
set: as_integer = i
end
make_from_integer_64 (i: INTEGER_64)
-- Initialize `Current' from `i'.
do
default_create
set_from_integer_64 (i)
ensure
set: as_integer_64 = i
end
make_from_integer_32 (i: INTEGER_32)
-- Initialize `Current' from `i'.
do
default_create
set_from_integer_32 (i)
ensure
set: as_integer_32 = i
end
make_from_integer_16 (i: INTEGER_16)
-- Initialize `Current' from `i'.
do
default_create
set_from_integer_16 (i)
ensure
set: as_integer_16 = i
end
make_from_integer_8 (i: INTEGER_8)
-- Initialize `Current' from `i'.
do
default_create
set_from_integer_8 (i)
ensure
set: as_integer_8 = i
end
make_from_natural (n: NATURAL)
-- Initialize `Current' from `n'.
do
default_create
set_from_natural (n)
ensure
set: as_natural = n
end
make_from_natural_64 (n: NATURAL_64)
-- Initialize `Current' from `n'.
do
default_create
set_from_natural_64 (n)
ensure
set: as_natural_64 = n
end
make_from_natural_32 (n: NATURAL_32)
-- Initialize `Current' from `n'.
do
default_create
set_from_natural_32 (n)
ensure
set: as_natural_32 = n
end
make_from_natural_16 (n: NATURAL_16)
-- Initialize `Current' from `n'.
do
default_create
set_from_natural_16 (n)
ensure
set: as_natural_16 = n
end
make_from_natural_8 (n: NATURAL_8)
-- Initialize `Current' from `n'.
do
default_create
set_from_natural_8 (n)
ensure
set: as_natural_8 = n
end
make_from_string (s: STRING)
-- Initialize `Current' from `s' where `s' is a base 10 string
require
s_not_empty: not s.is_empty
do
default_create
set_str (Current, s, 10)
end
make_from_hex_string (s: STRING)
-- Initialize `Current' from `s' where `s' is a base 16 string
require
s_not_empty: not s.is_empty
do
default_create
set_str (Current, s, 16)
end
make_from_string_base (s: STRING base: INTEGER)
-- Initialize `Current' from `s' where `s' is a string of base `base'
require
s_not_empty: not s.is_empty
base_too_small: base >= 2
base_too_big: base <= 62
do
default_create
set_str (Current, s, base)
end
make_random (bits_a: INTEGER)
-- Initialize as a random number of `bits_a' bits
require
valid_bits: bits_a > 0
do
default_create
set_random (bits_a)
ensure
correct_bits: bits <= bits_a
end
make_random_prime (bits_a: INTEGER)
-- Initialise a random number of `bits_a' bits that is probably prime
require
valid_bits: bits_a > 0
do
default_create
from
set_random (bits_a)
until
is_probably_prime
loop
set_random (bits_a)
end
ensure
prime: is_probably_prime
correct_bits: bits <= bits_a
end
make_from_bytes (bytes_array: SPECIAL[NATURAL_8] first: INTEGER last: INTEGER)
-- Initialize from byte array
require
last_after_first: last >= first
valid_offset: bytes_array.valid_index (first)
valid_end: bytes_array.valid_index (last)
do
default_create
input (Current, last - first + 1, 1, 1, -1, bytes_array, first)
end
make_random_max (max_value: like Current)
--Generate a uniform random integer in the range 0 to max_value-1, inclusive.
require
positive_max: max_value.is_positive
do
default_create
urandomm (Current, random_state, max_value)
ensure
valid_range: Current < max_value
end
make_limbs (limbs: INTEGER)
-- Initialize `Current' with space for `limbs' limbs in the internal representation
do
create item.make_filled (0, limbs)
count := 0
ensure
is_zero
end
make_bits (bits_a: INTEGER)
do
create item.make_filled (0, (bits_a + (limb_bits - 1)) // limb_bits)
count := 0
ensure
is_zero
end
feature -- Constants
one: like Current
-- Neutral element for "*" and "/"
deferred
end
zero: like Current
-- Neutral element for "+" and "-"
deferred
end
feature -- Comparison
is_less alias "<" (other: like Current): BOOLEAN
-- Is current object less than `other'?
do
Result := three_way_comparison (other) < 0
end
is_equal (other: like Current): BOOLEAN
-- Is `other' attached to an object considered
-- equal to current object?
do
Result := three_way_comparison (other) = 0
end
three_way_comparison (other: like Current): INTEGER
-- Perform a three way comparison between `Current' and `other'
do
Result := compare (Current, other).three_way_comparison (0)
end
feature -- Measurement
bytes: INTEGER
-- Minimum number of bytes the absolute value of this number would occupy
do
Result := (bits + 7).bit_and (0xfffffff8).bit_shift_right (3)
end
bits: INTEGER
-- Minimum number of bits the absolute value of this number would occupy
do
Result := size_in_base (2)
ensure
valid_result: Result >= 1
end
feature -- Status report
divisible (other: like Current): BOOLEAN
-- May `Current' be divided by `other'?
do
Result := not other.is_zero
end
exponentiable (other: NATURAL_32_REF): BOOLEAN
-- May `Current' be elevated to the power `other'?
do
Result := True
end
fits_natural: BOOLEAN
-- Does `Current' fit in a {NATURAL} without truncation?
do
Result := fits_natural_32
end
fits_natural_64: BOOLEAN
-- Does `Current' fit in a {NATURAL_64} without truncation?
local
n: INTEGER
do
resize (2)
n := count
Result := n >= 0 and n <= 2
end
fits_natural_32: BOOLEAN
-- Does `Current' fit in a {NATURAL_32} without truncation?
local
n: INTEGER
do
n := count
Result := n = 0 or n = 1
end
fits_natural_16: BOOLEAN
-- Does `Current' fit in a {NATURAL_16} without truncation?
local
n: INTEGER_32
do
n := count
Result := n = 0 or (n = 1 and then item [0] <= (0).to_natural_16.max_value)
end
fits_natural_8: BOOLEAN
-- Does `Current' fit in a {NATURAL_8} without truncation?
local
n: INTEGER_32
do
n := count
Result := n = 0 or (n = 1 and then item [0] <= (0).to_natural_8.max_value)
end
fits_integer: BOOLEAN
-- Does `Current' fit in an {INTEGER} without truncation?
do
Result := fits_integer_32
end
fits_integer_64: BOOLEAN
-- Does `Current' fit in an {INTEGER_64} without truncation?
local
n: INTEGER
limb1: NATURAL_32
limb2: NATURAL_32
do
n := count
limb1 := item [0]
if n = 0 or n = 1 or n = -1 then
Result := True
elseif n = 2 then
limb2 := item [1]
Result := not limb2.bit_test (31)
elseif n = -2 then
limb2 := item [1]
if limb2.bit_test (31) then
Result := limb2.bit_and (0x7fffffff) = 0 and limb1 = 0
else
Result := True
end
end
end
fits_integer_32: BOOLEAN
-- Does `Current' fit in an {INTEGER_32} without truncation?
local
n: INTEGER_32
limb: NATURAL_32
do
n := count
limb := item [0]
if
n = 0
then
Result := True
elseif n = 1 then
Result := not limb.bit_test (31)
elseif n = -1 then
if limb.bit_test (31) then
Result := limb.bit_and (0x7fffffff) = 0
else
Result := True
end
end
end
fits_integer_16: BOOLEAN
-- Does `Current' fit in an {INTEGER_16} without truncation?
local
n: INTEGER
limb: NATURAL_32
do
n := count
limb := item [0]
if n = 0 then
Result := True
elseif n = 1 then
Result := limb <= (0).to_integer_16.max_value.to_natural_32
elseif n = -1 then
Result := limb <= (0).to_integer_16.min_value.to_integer_32.abs.to_natural_32
else
Result := False
end
end
fits_integer_8: BOOLEAN
-- Does `Current' fit in an {INTEGER_8} without truncation?
local
n: INTEGER
limb: NATURAL_32
do
n := count
limb := item [0]
if n = 0 then
Result := True
elseif n = 1 then
Result := limb <= (0).to_integer_8.max_value.to_natural_32
elseif n = -1 then
Result := limb <= (0).to_integer_8.min_value.to_integer_32.abs.to_natural_32
end
end
is_odd: BOOLEAN
-- Is `Current' odd
do
Result := count /= 0 and then item [0].bit_test (0)
end
is_even: BOOLEAN
-- Is `Current' even?
do
Result := not is_odd
end
is_zero: BOOLEAN
-- Is `Current' equal to zero
do
Result := sign = 0
end
is_positive: BOOLEAN
-- Is `Current' positive
do
Result := sign = 1
end
is_negative: BOOLEAN
-- Is `Current' negative
do
Result := sign = -1
end
sign: INTEGER
-- Return the sign of `Current' where -1 is negative, 0 is zero, and 1 is positive
do
Result := count.three_way_comparison (0)
ensure
is_positive implies (Result = 1)
is_zero implies (Result = 0)
is_negative implies (Result = -1)
end
size_in_base (base: INTEGER): INTEGER
-- What is the size of the string representing the absolute value of `Current' in base `base'
require
base_too_small: base >= 2
base_too_big: base <= 62
do
Result := sizeinbase (Current, base)
end
feature -- Primality testing
is_composite: BOOLEAN
-- Is `Current' a composite number?
do
Result := probab_prime_p (Current, 10) = 0
end
is_prime: BOOLEAN
-- Is `Current' definitely a prime number?
do
Result := probab_prime_p (Current, 10) = 2
end
is_probably_prime: BOOLEAN
-- Is `Current' probably a prime number?
-- May return `False' if `Current' is actually prime.
do
Result := probab_prime_p (Current, 10) > 0
end
feature {INTEGER_X_FACILITIES}-- Element change
set_from_other (other: READABLE_INTEGER_X)
local
other_count: INTEGER
do
other_count := other.count
resize (other_count)
item.copy_data (other.item, 0, 0, other_count)
count := other_count
end
set_from_integer (value_a: INTEGER)
-- Initialize `Current' from `value_a'.
do
set_from_integer_32 (value_a)
ensure
value_a > 0 implies count = 1
value_a = 0 implies count = 0
value_a < 0 implies count = -1
fits_integer
as_integer = value_a
end
set_from_integer_64 (value_a: INTEGER_64)
-- Initialize `Current' from `value_a'
local
new_value: NATURAL_64
upper_limb: NATURAL_32
new_count: INTEGER
do
resize (2)
new_value := value_a.abs.to_natural_64
item [0] := new_value.to_natural_32
upper_limb := (new_value |>> 32).to_natural_32
item [1] := upper_limb
new_count := value_a.three_way_comparison (0)
new_count := new_count * ((upper_limb /= 0).to_integer + 1)
count_set (new_count)
ensure
value_a > 0 implies (count = 1 or count = 2)
value_a = 0 implies (count = 0)
value_a < 0 implies (count = -1 or count = -2)
fits_integer_64
as_integer_64 = value_a
end
set_from_integer_32 (value_a: INTEGER_32)
-- Initialize `Current' from `value_a'.
local
limb: NATURAL_32
do
if value_a < 0 then
limb := value_a.to_natural_32.bit_not + 1
else
limb := value_a.to_natural_32
end
item [0] := limb
count_set (value_a.three_way_comparison (0))
ensure
value_a > 0 implies count = 1
value_a = 0 implies count = 0
value_a < 0 implies count = -1
fits_integer_32
as_integer_32 = value_a
end
set_from_integer_16 (value_a: INTEGER_16)
-- Initialize `Current' from `value_a'.
local
limb: NATURAL_32
do
if value_a < 0 then
limb := value_a.to_natural_32.bit_not + 1
else
limb := value_a.to_natural_32
end
item [0] := limb
count_set (value_a.three_way_comparison (0))
ensure
value_a > 0 implies count = 1
value_a = 0 implies count = 0
value_a < 0 implies count = -1
fits_integer_16
as_integer_16 = value_a
end
set_from_integer_8 (value_a: INTEGER_8)
-- Initialize `Current' from `value_a'.
local
limb: NATURAL_32
do
if value_a < 0 then
limb := value_a.to_natural_32.bit_not + 1
else
limb := value_a.to_natural_32
end
item [0] := limb
count_set (value_a.three_way_comparison (0))
ensure
value_a > 0 implies count = 1
value_a = 0 implies count = 0
value_a < 0 implies count = -1
fits_integer_8
as_integer_8 = value_a
end
set_from_natural (value_a: NATURAL)
-- Initialize `Current' from `value_a'.
do
set_from_natural_32 (value_a)
ensure
value_a = 0 implies count = 0
value_a /= 0 implies count = 1
fits_natural
as_natural = value_a
end
set_from_natural_64 (value_a: NATURAL_64)
-- Initialize `Current' from `value_a'.
local
upper_limb: NATURAL_32
new_count: INTEGER
do
resize (2)
item [0] := value_a.to_natural_32
upper_limb := (value_a |>> 32).to_natural_32
item [1] := upper_limb
new_count := value_a.three_way_comparison (0)
new_count := new_count + (upper_limb /= 0).to_integer
count_set (new_count)
ensure
value_a = 0 implies count = 0
value_a /= 0 implies (count = 1 or count = 2)
fits_natural_64
as_natural_64 = value_a
end
set_from_natural_32 (value_a: NATURAL_32)
-- Initialize `Current' from `value_a'.
do
item [0] := value_a
if
value_a /= 0
then
count_set (1)
else
count_set (0)
end
ensure
value_a = 0 implies count = 0
value_a /= 0 implies count = 1
fits_natural_32
as_natural_32 = value_a
end
set_from_natural_16 (value_a: NATURAL_16)
-- Initialize `Current' from `value_a'.
do
item [0] := value_a.to_natural_32
if
value_a /= 0
then
count_set (1)
else
count_set (0)
end
ensure
value_a = 0 implies count = 0
value_a /= 0 implies count = 1
fits_natural_16
as_natural_16 = value_a
end
set_from_natural_8 (value_a: NATURAL_8)
-- Initialize `Current' from `value_a'.
do
item [0] := value_a.to_natural_32
if
value_a /= 0
then
count_set (1)
else
count_set (0)
end
ensure
value_a = 0 implies count = 0
value_a /= 0 implies count = 1
fits_natural_8
as_natural = value_a
end
set_from_string (s: STRING)
-- Initialize `Current' from `s' where `s' is a base 10 string
require
s_not_empty: not s.is_empty
do
set_str (Current, s, 10)
end
set_random (bits_a: INTEGER)
-- Initialize `Current' to random bits up to `bits_a' bits
require
valid_bits: bits_a >= 1
do
urandomb (Current, random_state, bits_a)
ensure
bits <= bits_a
end
feature -- Conversion with possible truncation.
-- Negatives wrap around in the negatives, non-negatives wrap around in the non-negatives
as_integer: INTEGER
-- Return the value of `Current' truncated to an {INTEGER}
do
Result := as_integer_32
end
as_integer_64: INTEGER_64
-- Return the value of `Current' truncated to an {INTEGER_64}
local
size: INTEGER
unsigned_result: NATURAL_64
do
size := count
if size > 1 then
unsigned_result := item [1].to_natural_64.bit_shift_left (32)
end
unsigned_result := unsigned_result.bit_or (item [0].to_natural_64)
if size > 0 then
Result := unsigned_result.to_integer_64.bit_and (0x7fff_ffff_ffff_ffff)
elseif size < 0 then
Result := (unsigned_result.to_integer_64 - 1).bit_and (0x7fff_ffff_ffff_ffff).bit_not
else
Result := 0
end
end
as_integer_32: INTEGER_32
-- Return the value of `Current' truncated to an {INTEGER_32}
local
size: INTEGER
zl: NATURAL_32
do
size := count
zl := item [0]
if size > 0 then
Result := zl.to_integer_32.bit_and (0x7fffffff)
elseif size < 0 then
Result := (zl.to_integer_32 - 1).bit_and (0x7fffffff).bit_not
else
Result := 0
end
end
as_integer_16: INTEGER_16
-- Return the value of `Current' truncated to an {INTEGER_16}
local
size: INTEGER
limb: NATURAL_32
do
size := count
limb := item [0]
if size > 0 then
Result := limb.to_integer_16.bit_and (0x7fff)
elseif size < 0 then
Result := (limb.to_integer_16 - 1).bit_and (0x7fff).bit_not
else
Result := 0
end
end
as_integer_8: INTEGER_8
-- Return the value of `Current' truncated to an {INTEGER_8}
local
size: INTEGER
limb: NATURAL_32
do
size := count
limb := item [0]
if size > 0 then
Result := limb.to_integer_8.bit_and (0x7f)
elseif size < 0 then
Result := (limb.to_integer_8 - 1).bit_and (0x7f).bit_not
else
Result := 0
end
end
as_natural: NATURAL
-- Return the value of the absolute value of `Current' truncated to a {NATURAL}
do