ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Common Board

How to use "sqrt" function without including <math.h>
Posted by OverAll 16 Apr 2003 02:03
I've got compilation error and I think it's because of including
math.h. Can you advise me something?
Re: How to use "sqrt" function without including <math.h>
Posted by Sam Green 16 Apr 2003 04:26
> I've got compilation error and I think it's because of including
> math.h. Can you advise me something?
I think your problem shouldn't be including <math.h>

as I quest , it might be this

int a;
double b;
....
b=sqrt(a); //compilation error here

because the parameter pass to sqrt is int , and sqrt in library here has
been overloaded for more than one argument type , but not for int. so
the compiler don't know which one to pick

it can be fix just by casting
int a;
double b;
....
b=sqrt((double)a); // can be compiled now

If you want to view error in more detail than online status page, submit
your solution via e-mail (read FAQ if you don't know how)

anyway if you really can't include <math.h> , implement you own sqrt
(one method is using numerical method)