I am attempting to write a modular inverse function based on this c++ version in my TI-Nspire CX.
So far I have the following code:
Define LibPub modinv(a,b)=
Func
Local b0,t,q,x0,x1
0→x0
1→x1
If b=1 Then
Return 1
EndIf
While a>1
q:=((a)/(b))
t:=b
b:=mod(a,b)
a:=t
t:=x0
x0:=x1-q*x0
x1:=t
EndWhile
If x1<0 Then
x1:=x1+b0
EndIf
Return x1
EndFunc
When I run the program
invmod(26,3)
I get this error:
Error: Variable is not defined
When I "view" the error it shows this line as being problematic (I think), as the cursor goes right to this line.
You didnt define b0, it has symbolic value. Since it is a local variable, you can not leave the scope, i.e. return x1 that contains symbolic b0 within.