Thread: pow() doesnt return a double?

  1. #16
    Registered User FloatingPoint's Avatar
    Join Date
    Jun 2003
    Posts
    191
    What does that mean?
    Can this opcode, whatever it is, be enabled/disabled?

    Thanx.
    Come cast your shadow over me
    and I'll cast mine all over thee
    Take me away, into the shades
    where there is no light of day

  2. #17
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    It means Bubba's answer is only relevant to assembler programmers on x86 machines.

    C and C++ programmers simply look at the prototypes of the functions involved to work out what they return
    Very true, but on all x86 and hybrids thereof (AMD, etc) this is an accurate statement.

    So obviously what is taking place is that somewhere a conversion is being done on the result which is why it is returning as an integral value. I've never had this problem with pow(), but I know why it is happening.

    There is nothing wrong with the pow() function in the math library and if you disassembled the program you could verify this fact. So the problem exists in either how you are using pow() or in how you are displaying the result.

    Unless you are programming on another platform other than x86 or not using C/C++, all floating point values are returned in st(0) or the first floating point register. There is no way possible for pow() to return an integral value since it does not place any integral values into (e)ax which is where all integral values are returned. This statement only applies to C/C++ since this is the system the designers used to be able to return values from functions.

    Salem is right in that you should be able to fix the problem w/o diving into the disassembly.

    <double/float> SomeFunc(void) - implies the result will be left in st(0)

    <unsigned/signed char, int, long> SomeFunc(void) - implies the result will be in (e)ax


    Granted assembler is not used much anymore and is not portable and blah, blah, blah...but it can be useful in debugging and very useful in games. It will give you a better idea of what is taking place in your C code and you will be able to read the disassembly that MSVC puts out.
    Last edited by VirtualAce; 07-31-2003 at 08:56 AM.

  3. #18
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    No conversion is done. cout formatting simply doesn't output any digits after the comma and thus not the comma either.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #19
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    It's a decimal point, not a comma you stupid European.

  5. #20
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by golfinguy4
    It's a decimal point, not a comma you stupid European.

    I'm a European and I use a decimal point......kind of throws me whenever I see any figures from the continent....

  6. #21
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    [sarcastic arrogance]Yeah, but you also like our cousin, you learn the best stuff from us.[/sarcastic arrogance]

  7. #22
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    If you weird guys ever start using any sane units for weight, length etc. we can talk again
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #23
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    When you get a good language (one that doesn't sound like you're coughing up your lungs while you're speaking), we can start talking.

  9. #24
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Um, what are you talking about? I'm not Dutch
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  2. C++ to C Conversion
    By dicon in forum C Programming
    Replies: 7
    Last Post: 06-11-2007, 08:38 PM
  3. functions and passing data
    By redmondtab in forum C Programming
    Replies: 41
    Last Post: 09-21-2006, 12:04 PM
  4. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  5. Unknown Math Issues.
    By Sir Andus in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2006, 06:54 PM