# Powers lower than 1

**URL:** <https://discourse.mc-stan.org/t/powers-lower-than-1/19778>\
**Category:** General\
**Created:** [December 13, 2020, 12:30am UTC](https://discourse.mc-stan.org/t/powers-lower-than-1/19778 "2020-12-13T00:30:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![l\_bartoszcze](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/l_bartoszcze/32/10138_2.png) [@l\_bartoszcze](https://discourse.mc-stan.org/u/l_bartoszcze)\
**Post date:** [December 13, 2020, 12:30am UTC](https://discourse.mc-stan.org/t/powers-lower-than-1/19778/1 "2020-12-13T00:30:35Z")

</div>

For some reason, Stan outputs NA for powers lower than one.  
This seems to be the case for both “^” and the pow() function.  
I don’t know if the error happens only on my machine, but seems to persist in both RmdStan and CmdStan.  
This happend when I tried to work with utility functions in stan and wrote something like  
PERIODU[t] = (C[t]\*1000/L[t])^(1-elasmu)-1)/(1-elasmu)-1;  
I was confused as to why this was an NA as I have defined C[t], L[t] (vectors of size t) and elasmu (a constant) before. Turns out, elasmu was 1.45, giving a power that could not be processed. I have tested this using simpler expressions, such as 2^(0.45) and the error persists. I don’t know if that is a common experience or maybe a result of my coding errors.  
I’d be grateful if anyone could share if that is the case on other machines too.

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [December 13, 2020, 1:25am UTC](https://discourse.mc-stan.org/t/powers-lower-than-1/19778/2 "2020-12-13T01:25:57Z")

</div>

Hi Lukasz, welcome to the Stan forums! Powers less than 1 should work fine, so perhaps there’s something going on with your particular Stan program or installation. Before asking you to share a reproducible example so we can look at your Stan code and try running it, let’s just check a super simple example. What happens if you run the following Stan program for just a couple of iterations? It tests a fractional power and a negative power:

```stan
parameters {
  real x;
}
model {
  print("x = ", x, ", x^0.5 = ", x^0.5, ", x^-3 = ", x^-3);
  x ~ std_normal();
}

```

You should see something like this:

```
Chain 1 x = 1.40705, x^0.5 = 1.18619, x^-3 = 0.358985 
Chain 1 x = -2.02891, x^0.5 = nan, x^-3 = -0.119732 
Chain 1 x = 1.40705, x^0.5 = 1.18619, x^-3 = 0.358985 

```

When `x` is positive there shouldn’t be any `nan` values, but for negative values of `x` you should get `nan` for `x^0.5`. What happens for you?

---

<div class="post-metadata">

**Author:** ![l\_bartoszcze](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/l_bartoszcze/32/10138_2.png) [@l\_bartoszcze](https://discourse.mc-stan.org/u/l_bartoszcze)\
**Post date:** [December 13, 2020, 1:52am UTC](https://discourse.mc-stan.org/t/powers-lower-than-1/19778/3 "2020-12-13T01:52:55Z")

</div>

Hi Jonah,  
Thanks for helping me on this.  
It works fine indeed. Turns out, the problem was caused by my misunderstanding of how the sampling functions. Thanks for clarifying that!

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [December 13, 2020, 2:48am UTC](https://discourse.mc-stan.org/t/powers-lower-than-1/19778/4 "2020-12-13T02:48:44Z")

</div>

Great, glad you worked it out.

I also meant to mention in my previous reply that if I had used `real<lower=0> x;` then there wouldn’t have been any `nan`s at all due to the positive constraint.
