function [tau,B,C] = scaleBC(B,C,SCALE)
% Computes scaling TAU such that TAU*B and C/TAU have approximately
% matching norms. If either B or C is zero, SCALE is used as target
% norm for TAU*B or C/TAU.

%   Copyright 2018 The MathWorks, Inc.
nB = max(abs(B(:)));
nC = max(abs(C(:)));
if nB>0
   if nC>0
      tau = pow2(round(log2(nC/nB)/2));
      B = tau*B;  C = C/tau;
   else
      tau = pow2(round(log2(SCALE/nB)));
      B = tau*B;
   end
else
   if nC>0
      tau = pow2(round(log2(nC/SCALE)));
      C = C/tau;
   else
      tau = 1;
   end
end