# Pow() doesn't handle fractional exponents

**URL:** https://discourse.processing.org/t/pow-doesnt-handle-fractional-exponents/1973
**Category:** Beginners
**Created:** [July 21, 2018, 9:26pm UTC](https://discourse.processing.org/t/pow-doesnt-handle-fractional-exponents/1973 "2018-07-21T21:26:03Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![rich](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@rich](https://discourse.processing.org/u/rich)
#### Post date: [July 21, 2018, 9:26pm UTC](https://discourse.processing.org/t/pow-doesnt-handle-fractional-exponents/1973/1 "2018-07-21T21:26:03Z")

</div>

Why doesn’t `pow()` properly handle fractional exponents, and is there a way to force it to? Decimal exponents such as 0.667 are handled correctly, but not fractions such as 2/3. For example, I’d expect

`float x = pow(8, 2/3);`

to return 4.0 for the value of `x`, but it returns 1.0. As another example,

`float x = pow(8, 3/2);`

returns 8.0. It seems `pow()` replaces a fraction with the next lowest integer.

---

<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 21, 2018, 9:32pm UTC](https://discourse.processing.org/t/pow-doesnt-handle-fractional-exponents/1973/2 "2018-07-21T21:32:35Z")

</div>

`2/3` is `0`.

Try using `2.0/3.0` instead.

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [July 22, 2018, 6:36am UTC](https://discourse.processing.org/t/pow-doesnt-handle-fractional-exponents/1973/3 "2018-07-22T06:36:36Z")

</div>

This is referred as an integer division in java as the division returns an integer. Easiest way to solve this is to make at least one of the terms float.

Kf

---

<div class="post-metadata">

### Author: ![madbrine](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/madbrine/32/7271_2.png) [@madbrine](https://discourse.processing.org/u/madbrine)
#### Post date: [July 28, 2018, 8:11pm UTC](https://discourse.processing.org/t/pow-doesnt-handle-fractional-exponents/1973/4 "2018-07-28T20:11:46Z")

</div>

One way is to change it to `float x = pow(8, 2.0/3);`
