How to Use pow Function in C for Trigonometric Expressions?

  • Thread starter pairofstrings
  • Start date
So, in summary, the expressions 1 and 3 are identical, and the power function pow() in the C math.h library can be used to raise a number to a power, but in this case, it is more efficient to simply multiply the number by itself.
  • #1
pairofstrings
411
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.
 
Technology news on Phys.org
  • #2
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.
 
  • #3
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 Drakkith

Similar threads

Replies
6
Views
1K
Replies
8
Views
3K
Replies
4
Views
1K
Replies
7
Views
1K
Replies
4
Views
2K
Replies
5
Views
2K
Back
Top