Program to calculate root of cubics

Programming, for all ages and all languages.
Post Reply
nullplan
Member
Member
Posts: 1767
Joined: Wed Aug 30, 2017 8:24 am

Program to calculate root of cubics

Post by nullplan »

Hi all,

had a bit of time on my hands and so I wrote something i wanted to implement for a while now, namely a program to calculate the roots of cubic expressions (by Cardano's method). Now I've written it, I am not entirely sure if I'm doing everything right. I added a check for the results at the end, and I regularly get results on the order of 1e-16. Is that entirely down to my non-optimized programming? Or did I get something wrong?
Attachments
cubic.c
source code
(7.35 KiB) Downloaded 126 times
Carpe diem!
Octocontrabass
Member
Member
Posts: 5513
Joined: Mon Mar 25, 2013 7:01 pm

Re: Program to calculate root of cubics

Post by Octocontrabass »

Double-precision values can accurately store around 15 decimal digits, so that sounds like normal rounding error.

By default, compilers don't change the order of floating-point operations while optimizing, so you may be able to improve the rounding error by changing how you calculate intermediate values.
Post Reply