# How to cube a sine/cosine function in processing

**URL:** <https://discourse.processing.org/t/how-to-cube-a-sine-cosine-function-in-processing/17257>\
**Category:** Coding Questions\
**Created:** [January 22, 2020, 5:30pm UTC](https://discourse.processing.org/t/how-to-cube-a-sine-cosine-function-in-processing/17257 "2020-01-22T17:30:34Z")\
**Posts on this page:** 1\
**Showing post:** 10

<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:** [January 25, 2020, 1:20am UTC](https://discourse.processing.org/t/how-to-cube-a-sine-cosine-function-in-processing/17257/10 "2020-01-25T01:20:22Z")

</div>

Hello,

Back to your original question…

> [@prathmesh](#):
>
> How do I write cos"raised to the power 3"(t) in my processing code?

This was the fastest (667) execution in my tests for your original request:

```auto
float angle = random(0, TAU);    
float tmp = cos(angle);
float cosCubed = tmp*tmp*tmp;

```

Compared to (1127):

```auto
float angle = random(0, TAU);
float cosCubed = cos(angle)*cos(angle)*cos(angle);

```

Slowest (1275) :

```auto
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 topic.

Processing:

```auto
cos();

```

Is a call to Java:

```auto
(float) Math.cos(angle);

```

You can find Processing cos() and pow() here in the source code if you are adventurous to see what it calls from Java:  
[https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java](https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java)

Slightly faster if you call the Java Math functions directly.

🙂

---

_[View the full topic](https://discourse.processing.org/t/how-to-cube-a-sine-cosine-function-in-processing/17257)._
