Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C/++/# Sin^2(x), sin(x^2), (sin(x))^2

  1. May 20, 2017 #1
    How to write
    1. sin2(x)
    2. sin(x2)
    3. (sin(x))2
    by using predefined function pow defined in math.h in C language?
    Are they all same?

    Thank you.
  2. jcsd
  3. May 20, 2017 #2


    User Avatar
    Staff Emeritus
    Science Advisor

    1 and 3 are identical. Sin2(x) = sin(x) * sin(x) = (sin(x))2.

    The power function in the C math.h library is defined as: double pow( double x, double y), where x is raised to the power of y.
    So you'll pass to the function sin(x) or x along with a two.
  4. May 20, 2017 #3


    Staff: Mentor

    Since all of these expressions involve only the power 2, you can get the same result by multiplying instead of using the pow() function. For #2 above, sin(x^2) is the same as sin(x * x), but the latter form takes considerably less time to compute.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted