I have attempted to separate the number of periods (n) from the following equation

pv (1 + i)^n + pmt (1 + i * type) [{(1 + i)^n - 1}/i] + fv = 0

Have I done this correctly?

type has either a value of 0 for end of period payments and 1 for start of period payments

n = log[ { pmt * ( 1 + i * type) - fv * i } / { pmt * ( 1 + i * type) + pv * i } ] / log( 1 + i * type)

Thanks