This is the BigInt example of Info file (included in M2000 setup file - see release on GitHub)
We can mix numbers with biginteger. Except for ^ power which biginteger downgrade (if it can't we get error), all other operations return biginteger, if a biginteger exist in the numeric expression.
Also comparison operators now work. When we compare a BigInteger with a different numeric type then that converted to BigInteger and then compared.
If we need a number (as a parameter) and that number is a biginteger then this converted to decimal, or an overflow error raised. So we can't pass a 40digit or a 200000 digits biginteger to a Color parameter;
Although internal a biginteger is an object, we get copies with normal use. There is a system which count references and decide if can copy or can pass the object. When we pass a BigInteger, a pointer copied to stack of values, but when we get the pointer then the system decide if it has to produce a copy. So we can pass a biginteger to stack of values and make some copies of stack items using Over statement, and there exist only one objects (with many pointers to it).
class alfa {
// 1000 converted to biginteger
biginteger a=1000
b=830808403294802384092380923840u
// using function we can convert from base (2 min to 36 max)
c=biginteger("FFFFFFFF", 16)
}
M=alfa()
? M.a, type$(M.a)
? M.b, type$(M.b)
? M.c, type$(M.c)
with M.c, "outputBase", 2
? M.c
z=m
// now z has z.c with same outputBase of 2 (binary). Internal has base 10. so when we print or using Str$() or using format$() we get the result of a conversion to the prefered base.
// there is no ++ for BigInteger
M.a=M.a+1
? Z.a+1=M.a ' true
M.b=M.b+1 ' we can use 1u as BigInteger literal value.
? Z.b+1=M.b ' true
M.c=M.c+1
? str$(M.c)="100000000000000000000000000000000"
clipboard str$(z.c)
? str$(z.c)="11111111111111111111111111111111"
? z.c+1=M.c
? format$("binary: {0}", z.c)
biginteger a=200
? type$(a)
Let b=a
? a=200, b=200
? type$(b)
alfa(&b)
? b=333, type$(b)
alfa1(&b)
? b=500, type$(b)
alfa2(b)
? b=500, type$(b)
? a=200
sub alfa(&k as biginteger)
k=333
end sub
sub alfa1(&k)
k=500
end sub
sub alfa2(k)
k=100
end sub
This is the BigInt example
bold 0
form 60, 44
a=848093284092840932840386876876876876892u
b=3432402938402820840923809880009089u
c=10000000000000000u
Print "a="+a
Print "b="+b
Print "c="+c
Print "a power b modules c (modpow(a,b,c)) = ";modpow(a,b,c)
c=10000000000000000u*50000000000000u-123456
z=c-1
Print "c="+c
Print "z="+z
Print "c=z+1 is ";c=z+1 ' true
Print "c*-1 is ";c*-1
c=c*-1
Print "Sgn(c) is ";Sgn(c)
Print "Abs(c) is ";Abs(c)
Print "Len of digitis plus minus of c is ";Len(Str$(c))
c=Abs(c)
Print "Square integer root of c = ";sqrt(c)
d=c mod# 23423984798324292834u
c=-abs(c)
Print "Negate c: ";c
Print "c mod# 23423984798324292834u (Euclid modulus) = d ="
Print d
dd=c div# 4545545454545454545u
Print "c div# 4545545454545454545u (Euclid division) = dd ="
print dd
Print "Modulus ";mod(dd)
Print "dd*4545545454545454545u+mod(dd)=c is ";dd*4545545454545454545u+mod(dd)=c
dd=c div 4545545454545454545u
Print "c div 4545545454545454545u = dd ="
print dd
Print "Modulus ";mod(dd)
Print "dd*4545545454545454545u+mod(dd)=c is ";dd*4545545454545454545u+mod(dd)=c
Print "Using fix decimal point (on rendering)"
for i=1 to 10
print format$("{0:6}", c+i*1e6)
next
s=Str$(c+i*1e6)
print len(s)
v=Val(format$("{0:6}@", c+i*1e6))
print Type$(v)
print "v=";v
v++
print "v=";v
print "Assign decimal to BigInteger - conversion like w euse int()"
c=v
?c, type$(c)
print "Assign decimal to BigInteger using ceil()"
c=ceil(v)
print c, type$(c)
bold 1
Print "Press F3"