Thread: cube root

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    12

    cube root

    how do you find this? i tried this:

    Code:
            fyards = (area ^ (1/3)); //cube root
    but i came up with this:

    63 C:\Dev-Cpp\program2.cpp invalid operands of types `float' and `int' to binary `operator^'

    help?

  2. #2
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    The power function is in the library <cmath>
    And it goes like this:
    Code:
    variable = pow(x,y);
    //Where x is what you want and y is the power
    double temp = pow(8,(1.0/3.0) ); //Will get you 2

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Alternative, if area is guaranteed to be greater than zero, would be;
    Code:
       fyards = exp(log(area)/3.0);

  4. #4
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Quote Originally Posted by grumpy
    Alternative, if area is guaranteed to be greater than zero, would be;
    Code:
       fyards = exp(log(area)/3.0);
    This is actually what the pow function does.

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Mathematically it is equivalent. As to it being what the pow() function actually does: that's implementation dependent. I suggest pow() will also do a few other things, otherwise it wouldn't work if the first argument is negative.

  6. #6
    ... arjunajay's Avatar
    Join Date
    May 2005
    Posts
    203
    ^ is the XOR operator by the way...

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by arjunajay
    ^ is the XOR operator by the way...
    Yup.

    But the way the question was asked he was using x^y as a notation for "x raised to the power of y".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer confusion
    By Blackroot in forum C++ Programming
    Replies: 11
    Last Post: 09-12-2007, 12:44 AM
  2. A cube root program.
    By guest111 in forum C Programming
    Replies: 14
    Last Post: 04-27-2007, 09:37 PM
  3. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Templated Binary Tree... dear god...
    By Nakeerb in forum C++ Programming
    Replies: 15
    Last Post: 01-17-2003, 02:24 AM