import math def cubic(a,b,c): q = a*a/9 - b/3 r = (a*a/27 - b/6)*a + c/2 s = a/-3 d = r*r - q*q*q if d > 0: t = (math.sqrt(d) + abs(r)) ** (1/3) u = (t + q/t) return s - u if r > 0 else s + u else: t = math.atan2(math.sqrt(-d), r) / 3 u = 2 * math.sqrt(q) return ( s - u * math.cos(t), s - u * math.cos(t + 2/3*math.pi), s - u * math.cos(t - 2/3*math.pi) ) print( cubic(10,10,-10) )