Version 4
SHEET 1 992 680
WIRE -416 144 -464 144
WIRE -416 192 -464 192
WIRE 656 192 464 192
WIRE 464 224 464 192
WIRE -416 240 -464 240
WIRE -416 304 -464 304
WIRE -416 352 -464 352
WIRE 464 368 464 304
WIRE -416 400 -464 400
FLAG -464 144 A0
IOPIN -464 144 In
FLAG -464 192 A1
IOPIN -464 192 In
FLAG -464 240 A2
IOPIN -464 240 In
FLAG -464 304 B0
IOPIN -464 304 In
FLAG -464 352 B1
IOPIN -464 352 In
FLAG -464 400 B2
IOPIN -464 400 In
FLAG 656 192 S
IOPIN 656 192 Out
FLAG 464 368 0
SYMBOL bv 464 208 R0
SYMATTR InstName B1
SYMATTR Value V=compare()
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
TEXT -232 312 Left 0 !.func compare(){if(numA()<numB(),-5,if(numA()>numB(),5,0))}
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)))}
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)))}
