# Coding Different Trigonometric Functions in Processing

**URL:** <https://discourse.processing.org/t/coding-different-trigonometric-functions-in-processing/22257>\
**Category:** Coding Questions\
**Created:** [June 29, 2020, 6:07pm UTC](https://discourse.processing.org/t/coding-different-trigonometric-functions-in-processing/22257 "2020-06-29T18:07:55Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 5, 2020, 3:09pm UTC](https://discourse.processing.org/t/coding-different-trigonometric-functions-in-processing/22257/17 "2020-07-05T15:09:53Z")

</div>

> [@Chrisir](#):
>
> I also heard that pow is really slow
> 
> You can write a function where the multiplying is done in a for loop x times without pow

You can write a function for **integer exponents** and where execution time is important to speed things up.  
Discussed and tested here:

> [@How to cube a sine/cosine function in processing](https://discourse.processing.org/t/how-to-cube-a-sine-cosine-function-in-processing/17257/10):
>
> Hello, Back to your original question… This was the fastest (667) execution in my tests for your original request: float angle = random(0, TAU); float tmp = cos(angle); float cosCubed = tmp\*tmp\*tmp; Compared to (1127): float angle = random(0, TAU); float cosCubed = cos(angle)\*cos(angle)\*cos(angle); Slowest (1275) : float angle = random(0, TAU); float cosCubed = pow(cos(angle), 3); The numbers (ms) were the outcome of a stress test using modified code from @jeremydouglass in this to…

In the example provided he did not require pow():

```auto
float x;
float y;

void setup()
  {
  size(500, 500);
  strokeWeight(2);
  translate(width/2, height/2 - 10);

//Using integer steps in formula used  
for (int i = -10; i<10; i+= 1)
    {
    y = 200/(1+pow(exp(1), i));
    point(10*i, 1-y);
    }

  translate(0, height/2);    
    
// Simplified and using float steps of 0.5 
  for (float i = -10; i<10; i+= .5)
    {
    y = 200/(1+exp(i));
    point(10*i, 1-y);
    }
  }

```

References:

> **[exp() / Reference](https://processing.org/reference/exp_.html)**
>
> Returns Euler's number e (2.71828...) raised to the power of the value parameter.

> **[pow() / Reference](https://processing.org/reference/pow_.html)**
>
> Facilitates exponential expressions. The pow() function is an efficient way of multiplying numbers by themselves (or their reciprocal) in large quantities. For example, pow(3, 5) is equi…

[Processing source code for exp() and pow()](https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java#L4513)

`:)`

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/3c4efcb083821d404c74959b166537f71deb38d9.png)

---

_[View the full topic](https://discourse.processing.org/t/coding-different-trigonometric-functions-in-processing/22257)._
