Using Julia and Polynomials.jl (<https://juliamath.github.io/Polynomials.jl/stable/>) with Nimjl <https://github.com/clonkk/nimjl>) - I used this method in the past for Polynomial of any order import nimjl Julia.init(1): Pkg: add("Polynomials") jlUseModule("Polynomials") var p = Julia.Polynomial([1, 12, -4, 8]) echo p #1 + 12*x - 4*x^2 + 8*x^3 var s = Julia.roots(p) echo s # ComplexF64[-0.08080510243721191 + 0.0im, 0.29040255121860614 - 1.2093793342224015im, 0.29040255121860614 + 1.2093793342224015im] Run
Using a raw Nim you probably want to start at : <https://github.com/SciNim/polynumeric> but it's more experimental. import polynumeric var p = Poly(cofs: @[8'f32, -4, 12, 1]) var s = p.roots() echo s Run That said for finding read roots of a cubic polynomial it does the job. If you need more advanced functionality, feel free to open a PR. Like @xigoi said, the formulas aren't that complicated.