3 WIRE -416 144 -464 144
\r
4 WIRE -416 192 -464 192
\r
7 WIRE -416 240 -464 240
\r
8 WIRE -416 304 -464 304
\r
9 WIRE -416 352 -464 352
\r
10 WIRE 464 368 464 304
\r
11 WIRE -416 400 -464 400
\r
27 SYMBOL bv 464 208 R0
\r
29 SYMATTR Value V=compare()
\r
30 TEXT -176 -232 Left 0 !.param V_N_max=-2 ; TODO: put in a library file\n.param V_P_min=2\n.func is_i(A){if(A<={V_N_max},5,0)}\n.func is_1(A){if(A>={V_P_min},5,0)}\n.func is_0(A){if(is_i(A) | is_1(A),0,5)}\n.func isnt_0(A){if(is_i(A) | is_1(A),5,0)}\n.func choose(A,for_n,for_z,for_p) {if(is_i(A),for_n,if(is_1(A),for_p,for_z))}\n.func tdiscrete(A){choose(A,-1,0,1)} ; make -1, 0, or 1
\r
31 TEXT -232 312 Left 0 !.func compare(){if(numA()<numB(),-5,if(numA()>numB(),5,0))}
\r
32 TEXT -240 80 Left 0 !; Sign of balanced trinary number (most-significant non-zero trit)\n.func tsign(c,b,a){if(isnt_0(c),c,if(isnt_0(b),b,if(isnt_0(a),a,0)))}
\r
33 TEXT -360 208 Left 0 !.func num(c,b,a){a*(3**0) + b*(3**1) + c*(3**2)}\n.func numA(){num(tdiscrete(V(A2)),tdiscrete(V(A1)),tdiscrete(V(A0)))}\n.func numB(){num(tdiscrete(V(B2)),tdiscrete(V(B1)),tdiscrete(V(B0)))}
\r