# Using pow() for non-integers

**URL:** <https://discourse.processing.org/t/using-pow-for-non-integers/2246>\
**Category:** Coding Questions\
**Created:** [July 31, 2018, 7:37pm UTC](https://discourse.processing.org/t/using-pow-for-non-integers/2246 "2018-07-31T19:37:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevenette](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@stevenette](https://discourse.processing.org/u/stevenette)\
**Post date:** [July 31, 2018, 7:37pm UTC](https://discourse.processing.org/t/using-pow-for-non-integers/2246/1 "2018-07-31T19:37:12Z")

</div>

I am trying to raise X ^ 0.026 using

```auto
float X = 2.0;
float Y = pow(X,0.026);

```

This returns 0.0 when it should return 1.018.

Does pow() require an integer? Is there a way around this? I have also tried

```auto
float Y = exp(0.026*log(X));

```

and I still return 0.0.

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [July 31, 2018, 7:47pm UTC](https://discourse.processing.org/t/using-pow-for-non-integers/2246/2 "2018-07-31T19:47:41Z")

</div>

```auto
float X = 2.0;
float Y = pow(X,0.026);
println( Y ); // Prints 1.0181853

```

I’m not having a problem with it. How are you seeing the value of Y?

---

<div class="post-metadata">

**Author:** ![stevenette](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@stevenette](https://discourse.processing.org/u/stevenette)\
**Post date:** [July 31, 2018, 7:55pm UTC](https://discourse.processing.org/t/using-pow-for-non-integers/2246/3 "2018-07-31T19:55:40Z")

</div>

I have no idea why it works now. In my code I had

```auto
float X = 2;

```

and I changed it to

```auto
float X = 2.0;

```

and now it works…sigh.

---

<div class="post-metadata">

**Author:** ![tony](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tony/32/949_2.png) [@tony](https://discourse.processing.org/u/tony)\
**Post date:** [July 31, 2018, 8:40pm UTC](https://discourse.processing.org/t/using-pow-for-non-integers/2246/4 "2018-07-31T20:40:25Z")

</div>

I know it works now, but can I ask if this is Processing.js or regular Java Processing?

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [July 31, 2018, 8:41pm UTC](https://discourse.processing.org/t/using-pow-for-non-integers/2246/5 "2018-07-31T20:41:44Z")

</div>

> [@stevenette](#):
>
> Does pow() require an integer?

Processing is open-source, so you can view its source [here](https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java). The `pow()` function is defined on line [4469](https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java#L4469).

```auto
static public final float pow(float n, float e) {
    return (float)Math.pow(n, e);
}

```

This defers to the `Math.pow()` function in Java, which you can read about [here](https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#pow-double-double-). The `Math.pow()` function takes `double` values as parameters, so no, `pow()` does not require integers.

This also works okay for me:

```auto
float x = 2;
float y = pow(x, 0.026);
println(y);

```

My best guess is you maybe had something like this:

```auto
float x = 1/2;
float y = pow(x, 0.026);
println(y);

```

With this code, the `1/2` calculation is done first, and since they’re both `int` primitives, the result is `0`.

Or maybe something like this:

```auto
float x = 2;
float y = pow(X, 0.026);
println(y);

```

Note the upper-case `X` in the second line of code. This `X` is a predefined value used internally by Processing, and its value is `0`.

---

<div class="post-metadata">

**Author:** ![stevenette](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@stevenette](https://discourse.processing.org/u/stevenette)\
**Post date:** [July 31, 2018, 10:10pm UTC](https://discourse.processing.org/t/using-pow-for-non-integers/2246/6 "2018-07-31T22:10:05Z")

</div>

Up in the top corner it just says Java

---

<div class="post-metadata">

**Author:** ![tony](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tony/32/949_2.png) [@tony](https://discourse.processing.org/u/tony)\
**Post date:** [August 1, 2018, 12:00am UTC](https://discourse.processing.org/t/using-pow-for-non-integers/2246/7 "2018-08-01T00:00:17Z")

</div>

> [@Kevin](#):
>
> This `X` is a predefined value used internally by Processing, and its value is `0` .

This sounds like it may be your culprit.
