How to Use pow Function in C for Trigonometric Expressions?

  • Context:
  • Thread starter Thread starter pairofstrings
  • Start date Start date
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 2K views
pairofstrings
Messages
411
Reaction score
7
Hello.
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.
 
Physics news on Phys.org
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.
 
pairofstrings said:
Hello.
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.
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.
 
  • Like
Likes   Reactions: Drakkith