OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:04 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Program to calculate root of cubics
PostPosted: Wed Jul 22, 2020 11:27 am 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1593
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:
File comment: source code
cubic.c [7.35 KiB]
Downloaded 40 times

_________________
Carpe diem!
Top
 Profile  
 
 Post subject: Re: Program to calculate root of cubics
PostPosted: Wed Jul 22, 2020 8:48 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 42 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group