## Refactoring #1732

Updated by wuttke over 2 years ago

SpecularMatrix::calculateUpFromLayer contains an innermost loop.

For thick multilayer system with few scattering layers, this loop dominates the overall computation time. Therefore stringent optimization is in order.

- Precompute aux = std::exp(ix), and divide by aux instead

of multiplying with std::exp(-ix).

- Use exp_I(x) from Complex.h instead of exp(I*x)

- And most importantly, use bisection instead of linear search to determine from which layer the computation can be started without running into overflow.

For thick multilayer system with few scattering layers, this loop dominates the overall computation time. Therefore stringent optimization is in order.

- Precompute aux = std::exp(ix), and divide by aux instead

of multiplying with std::exp(-ix).

- Use exp_I(x) from Complex.h instead of exp(I*x)

- And most importantly, use bisection instead of linear search to determine from which layer the computation can be started without running into overflow.