We're glad you came by, but you might find what you're looking for elsewhere.
TI-Basic Developer is not the site it once was. While its information on commands and other calculator features remains almost second-to-none, its forum, archives, and even hosting service, Wikidot, have been decaying for years. The calculator community would love to see what you're working on, or help you in your next coding adventure, but TI-Basic Developer is no longer the place to do it.
Instead, you should head over to Cemetech (primarily American) or TI-Planet (primarily international). Both are active, well-established forums with their own archives, chatrooms, reference material, and abundant coding tools and resources. We'll see you there, we hope.
I am attempting to write a modular inverse function based on this c++ version
#include <iostream>
using namespace std;
int mul_inv(int a, int b)
{
int b0 = b, t, q;
int x0 = 0, x1 = 1;
if (b == 1) return 1;
while (a > 1) {
q = a / b;
t = b, b = a % b, a = t;
t = x0, x0 = x1 - q * x0, x1 = t;
}
if (x1 < 0) x1 += b0;
return x1;
}
int main(void) {
cout<<mul_inv(42, 2017)<<endl;
return 0;
}
in my TI-Nspire CX So far I have the following code but am getting variable not defined in if statement.
Here is the code I have in my Nspire CX so far.
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
the inspire is throwing an error on this line.
If x1<0 Then
x1:=x1+b0
EndIf
Not sure what I am doing wrong here! Any insight would be appreciated!
I don't have my nspire to test on, but it looks like you are creating a function, so maybe you need something like this at the top:
Local x0,x1,q,t
Also, what is b0? Do you mean to use b? You don't seem to have it declared anywhere. I hope you figure it out; I always like a good mod inverse :)
EDIT: Wow, I have no idea how I missed that you already had that Local definition at the top, sorry!
Z80 Assembly>English>TI-BASIC>Python>French>C>0