Since years there was a polynomial solver builded in the POV-Ray™ sources. Unfortunately this tool was only for the intersection calculations in the raytracing engine. My idea was to create a gate between SDL and this existing solver.
All changes required for this feature are marked with POLYNOMIAL_SOLVER_PATCH
The polynomial solver in SDL was designed only as a gate to an already implemented feature. It was used previously only for the intersection point. Every next intersection point is almost always different from the previous one because it is calculated with different polynomial equations. In the case of the polynomial solver accessed via SDL in its proposed form it is possible that it is called several times: first for the number of roots and next for each root. That's why before the access to old solver polynomials are cached now (only for SDL usage). This is done with the function buffered_polynomial_solver() in the polysolv.cpp file. The whole change was splitted into three parts:
The complete operations within classic POV-Ray parser was placed inside Parse_Num_Factor() in express.cpp. The order of polynomial is read from the number of parameters there and then buffered_polynomial_solver() is called.
In case of VM in function engine this was a much more difficult operation. n_roots and nth_root have variable number of parameters. It is different than other functions works and it required new handling. First new entries were added at beginning of POVFPU_Opcodes structure in fnpovfpu.cpp. Then a gate between parser and precompiled opcodes was introduced to FNCode::compile_call in fncode.cpp with appropriate calls to dedicated compilers for new functions. Finally runtime code for new opcodes was added to POVFPU_RunDefault in fnpovfpu.cpp.