1. BigInteger class
We can put an outbase for toString function, so each time we get the string using the saved base of numbers.
Also we can create integers using an input base.
// methods
// MULTIPLY, DIVIDE, SUBTRACT, ADD, ANYBASEINPUT, MODULUS, INTPOWER
a=bigInteger("6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151")
b=bigInteger("162259276829213363391578010288127987979798")
method a, "multiply", b as c
method c, "add", biginteger("500") as c
with a, "tostring" as ret1
Print "A=";
Print ret1
Print
with b, "tostring" as ret2
with c, "tostring" as ret3
Print "B=";
Print ret2
Print
Print "C=";
Print ret3
method c, "divide", b as d
with c, "reminder" as export_reminder
with d, "tostring" as ret4
Print
Print "D=";
Print ret4
Print
Print "C/B reminder=";
Print export_reminder
reminder=biginteger(export_reminder)
method reminder,"compare", biginteger("500") as int1
Print "compare reninder with 500:";int1
method a, "AnyBaseInput", "FFFFFFFF", 16
Print "A=";
Print ret1
method a, "AnyBaseInput", "FFFFFFFFFFFFFFFF", 16
Print "A=";
Print ret1
method a, "AnyBaseInput", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16
Print "A=";
Print ret1
method a, "AnyBaseInput", "16"
with a, "OutputBase", 2
Print "A=";
Print ret1
method a, "intpower", biginteger("100", 2) as a
Print "A=";
Print ret1
method a, "subtract", biginteger("10000000000", 2) as a
Print "A=";
Print ret1
//method a, "AnyBaseOuput", 2 as retBin$
//? retBin$
2. Using Math and Math2 (new library) and the UDT values (user defined types) from there:
declare global m math2
method m,"cxone" as one
method m,"cxzero" as zero
function disp(a as cxComplex) {
string ret
vi=a|i
vr=a|r
if vi then
if vr then
if vi>0 then
if vi==1 then
ret="("+vr+"+i)"
else
ret="("+vr+"+"+vi+"i)"
end if
else
if vi==-1 then
ret="("+vr+"-i)"
else
ret="("+vr+""+vi+"i)"
end if
end if
else
if vi=1 then
ret="(i)"
else.if vi=-1 then
ret="(-i)"
else
ret="("+vi+"i)"
end if
end if
else
ret="("+vr+")"
end if
=ret
}
function complex(a, b) {
method m, "cxNew", a, b as ret
=ret
}
function inv(a) {
method m, "cxInv", a as ret
=ret
}
function mul(a, b) {
method m, "cxMul", a, b as ret
=ret
}
function div(a, b) {
method m, "cxDiv", a, b as ret
=ret
}
function add(a, b) {
method m, "cxAdd", a, b as ret
=ret
}
function sub(a, b) {
method m, "cxSub", a, b as ret
=ret
}
function exp(a, r=13) {
method m, "cxExp", a as ret
ret|r=round(ret|r, r)
ret|i=round(ret|i, r)
=ret
}
function Arg(a) {
method m, "cxArg", a as ret
=ret
}
function Cabs(a) {
method m, "cxMod", a as ret
=ret
}
A=complex(8, -3)
? "A=";disp(A)
? " r=";Cabs(A);" θ=";Arg(A);" rad"
B=inv(A)
? "B=";disp(B)
? " r=";Cabs(B);" θ=";Arg(B);" rad"
C=mul(A, B)
? disp(A);"*";disp(B);"=";disp(C)
D=div(one, B)
? disp(one);"/";disp(B);"=";disp(D)
E=div(A, A)
? disp(A);"/";disp(A);"=";disp(E)
F=add(A, A)
? disp(A);"+";disp(A);"=";disp(F)
G=sub(A, A)
? disp(A);"-";disp(A);"=";disp(G)
H=sub(zero, A)
? "-";disp(A);"=";disp(H)
? "(round exp to 13th decimal)"
I=add(exp(complex(0, pi)), one)
? "e^(πi)+1=";disp(i)
? "(without rounding)"
I=add(exp(complex(0, pi), 20), one)
? "e^(πi)+1=";disp(i)
Dim a(100)=a
Print a(2)|r, a(2)|i
variant z[100]
z[3]=a
Print z[3]|r, z[3]|i
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου
You can feel free to write any suggestion, or idea on the subject.