Used ldexp to quickly calculate power of two and made a separate function to calculate tangent numbers increasing code reuse.