Thread: Another Question!

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    4

    Question Another Question!

    I'm still not clear what this means:

    "Explain why pow(4,1/2) gives 1.0, but pow(4,0.5) gives 2.0 where pow(x,y) is the library function that calculates xy."

    I know that the second argument of pow( 4, 1/2 ) is not "one-half". It is 1 divided by 2. That is not the same as 0.5 since the compiler sees 1 as an integer and 1.0 as a float. So in C, 1.0 / 2.0 == 0.5, but 1 / 2 == 0.

    Yeah I understand all the above.....It's the bit about the lirary function I don't uderstand?
    Can anyone explain this to me?
    Cheers.
    Gaz.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    The library function has nothing to do with it - you need to look into the properties of integer division

  3. #3
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    C, as a language, is pretty flexible. There's a variant of C for pretty much every chip or OS out there. To accomplish this without changing the base language, there are many libraries that are used with it. These include things like stdio (for input and output), libs for file i/o, and math.h (where pow is from)

  4. #4
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    does 0.5 equals 0 ?

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    1

    Cool

    Friend you know
    when an integer is divided by an integet it result an integer. it skip the part after decimal so when 1 is divide by 2 it result 0.5 so
    5 is skipped after the decimal and u get 0 and any thing raised to power 0 is 1 . that is the answer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM