Sign in

Cmath V/S Math.H

 
Print Email
Here's a problem with cmath and math.h:

With gcc set up, math.h just contains the the usual C function pow(double, double) - so all the functions work because with pow(int, int) both ints get promoted to double by compiler and all is OK.
cmath in more than a wrapper for math.h. First it includes math.h and then undefines a whole lot of stuff that math.h defined, and substitutes the c++ versions.
This includes the pow function declaration.
As the c++ overloaded functions (same as any other c++ compiler), you will get the ambiguity problem - when using pow(int, int).

P.S.- The ambiguity occurs with pow(int, int) because integers can be promoted to floats or doubles, which means that pow(int, int) can fit the so overloaded c++ pow function - so the compiler gets confused.

* * * * *
Sign Up For a Roundup of The Week's Top Bloggers
Email:
SiliconIndia About Us   |   Contact Us   |   Help   |   Community rules   |   Advertise with us   |   Sitemap
News:       Technology   |   Enterprise   |   Tech Products   |   Startups   |   Finance   |   Business   |   Career   |   Magazine  |   Dailydose   |   News archive  
Cities:         Startup   |   CIO   |   Cloud   |   QA   |   BI   |   Women   |   Finance   |   Real Estate   |   Gadgets   |   Travel   |   HR   |   Marketing   |   SME  
Network:      Network   |   Profile   |   Messages   |   Find   |   Blogs   |   Events   |   Q&A   |   CXO Insights  
Career:      Jobs   |   Companies   |   Mentorship   |   Videos   |   Career blogs  |   Training Institute  |   Freshers
Online courses:   Web developer   |   Java developer   |   CCNA training   |   SEO   |   SAS   |   SQL server 2005   |   J2EE
Education:   MBA   |   MCA   |   Engineering   |   Overseas Education   |   Internship
Life:           Jokes   |   Bookstore   |   Relocate  |   Marketplace
Send your and help us continue to improve SiliconIndia
© 2012 SiliconIndia all rights reserved