Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,22 @@
procedure main()
SetupComplex()
a := complex(1,2)
b := complex(3,4)
c := complex(&pi,1.5)
d := complex(1)
e := complex(,1)
every v := !"abcde" do write(v," := ",cpxstr(variable(v)))
write("a+b := ", cpxstr(cpxadd(a,b)))
write("a-b := ", cpxstr(cpxsub(a,b)))
write("a*b := ", cpxstr(cpxmul(a,b)))
write("a/b := ", cpxstr(cpxdiv(a,b)))
write("neg(a) := ", cpxstr(cpxneg(a)))
write("inv(a) := ", cpxstr(cpxinv(a)))
write("conj(a) := ", cpxstr(cpxconj(a)))
write("abs(a) := ", cpxabs(a))
write("neg(1) := ", cpxstr(cpxneg(1)))
end

View file

@ -0,0 +1,27 @@
link complex # for complex number support
procedure SetupComplex() #: used to setup safe complex
COMPLEX() # replace complex record constructor
SetupComplex := 1 # never call here again
return
end
procedure COMPLEX(rpart,ipart) #: new safe record constructor and coercion
initial complex :=: COMPLEX # get in front of record constructor
return if /ipart & (type(rpart) == "complex")
then rpart # already complex
else COMPLEX( real(\rpart | 0.0), real(\ipart|0) ) # create a new complex number
end
procedure cpxneg(z) #: negate z
z := complex(z) # coerce
return complex( -z.rpart, -z.ipart)
end
procedure cpxinv(z) #: inverse of z
local denom
z := complex(z) # coerce
denom := z.rpart ^ 2 + z.ipart ^ 2
return complex(z.rpart / denom, z.ipart / denom)
end