def reduce_angle2(a,k0=nil) # divisor of pi or nil for pi*2
        # we could reduce first to pi*2 to avoid the mod k0 operation
        k,r,divisor = num_class.context do
          num_class.context.precision *= 3
          m = k0.nil? ? one_cycle : half_cycle/k0
          a.divmod(m)+[m]
        end
        [r, k.modulo(k0*2).to_i, divisor]
      end
def reduce_angle2(a,k0=nil) # divisor of pi or nil for pi*2
        # we could reduce first to pi*2 to avoid the mod k0 operation
        k,r,divisor = num_class.context do
          num_class.context.precision *= 3
          m = k0.nil? ? one_cycle : half_cycle/k0
          a.divmod(m)+[m]
        end
        [r, k.modulo(k0*2).to_i, divisor]
      end
Reduce angle to [0,Pi/k0) (result is not rounded to precision)