CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2010
    Posts
    3

    exp with floats and doubles

    hi

    i am running a program in C++ that calls (amongst other things) the exp function several hundred times. When i use doubles the program runs approx 10% faster than with floats. Can anyone explain why this might be?

    cheers
    richard

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: exp with floats and doubles

    Which one from a lot of exp types are you using?

    //edit: ... and how did you measure and for what build?
    Victor Nijegorodov

  3. #3
    Join Date
    Jun 2010
    Posts
    3

    Re: exp with floats and doubles

    hi

    i am using c++ under Gcc. As i understand it, in this system the compiler automatically selects the appropiate exp for example expf for a float. One cannot specify which type of exp to use.

    http://www.cplusplus.com/reference/clibrary/cmath/exp/

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: exp with floats and doubles

    Quote Originally Posted by riched158 View Post
    Well, I don't know how Gcc implements this function but assuming your link:
    Portability
    In C, only the double version of this function exists with this name.
    I'd guess that Gcc may use casting/converting operations for floats to double and back to use only this variant:
    Code:
      double exp (      double x );
    BTW, you haven't answer how you measured...
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured