# Why is math.noise(0.5, 0.5, 0.5) ^ 0.6 = nan?

I’m trying to do `math.noise(0.5, 0.5, 0.5) ^ 0.6` but its returning `nan`

``````local value = math.noise(0.5, 0.5, 0.5) -- this is -0.25
local value = math.noise(0.5, 0.5, 0.5) ^ 0.6 -- this is nan
local value = -0.25 ^ 0.6 -- this is -0.43527528164806206
``````

how would I get the value `-0.43527528164806206` when doing `math.noise(0.5, 0.5, 0.5) ^ 0.6`?

currently I’m doing

``````local noise = math.noise(0.5, 0.5, 0.5)
local value = if noise < 0 then -(-noise) ^ 0.6 else noise ^ 0.6
``````

but feels a bit ugly to me

2 Likes

You can do this:

``````local value = math.sign(noiseValue)*math.abs(noiseValue)^0.6
``````
2 Likes

The reason the difference occurs is due to the priority of the math operations, basically when you run `math.noise(0.5, 0.5, 0.5)^0.6` what you do is `(-0.25)^0.6`(the power is applied to the negative number), but when you run `-0.25^0.6` directly what you do is `0.25^0.6` and then reverse the sign(so the power operation runs on the positive number). According to what I noticed all negative numbers(like -0.25), when powered to a power less than 1(like 0.6) return `nan`.

So the solution is what @dthecoolest said, use the positive number only, then add back the sign:

``````print(math.sign(noise)*math.abs(noise)^0.6)
``````
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.