1

Is there a way to calculate powers of doubles in GLSL?

The pow function gives me this error when trying to use doubles:

unable to find compatible overloaded function "pow(float64_t, float)"

2 Answers2

1

According to this:

the extension is missing any goniometric,pow,exp,log functions.

So you can not use 64bit pow nor encode it using log,exp approach. You still might be able to implement Power by squaring or your own log,exp functions for this. I think for that exact reason they added these:

genDType frexp(genDType x, out genIType exp);
genDType ldexp(genDType x, in genIType exp);

However I never used them I just found them while searching the doc for log/exp/pow functions. Also implementing pow in GLSL will be a hard work due to lack of breakpoints, stepping/tracing ... This might help a lot:

But still I suggest to implement this on CPU side first and once working then port to GLSL.

Spektre
  • 49,595
  • 11
  • 110
  • 380
  • The reason I need doubles is because im writing a shader to zoom into the mandelbrot set. I need pow to calculate the distance to each point. Im not sure if it even has to be double precision, but it looks weird when zoomed in too far. Im just trying to replace all floats with double. –  Mar 28 '21 at 10:30
  • @Kport you do not need `pow` for that as Mandelbrot does not have any pow in its equation And the `sqr(x)` can be simply done by `x*x` see [Can't find a way to color the Mandelbrot-set the way i'm aiming for](https://stackoverflow.com/a/56197067/2521214) and [how do I get infinitely small numbers (for fractals)](https://stackoverflow.com/a/65018319/2521214) – Spektre Mar 28 '21 at 12:43
-1

pow requires both arguments to be the same. You can take a look at the documentation here. You could probably cast the variable before using pow:

pow(float(your_variable), the_power);

or

pow(your_variable, float64_t(the_power));

As I have never worked with float64_t before, I am not sure this will work. I am pretty sure the first one will, though.

Dharman
  • 30,962
  • 25
  • 85
  • 135
42yeah
  • 91
  • 7
  • The first one works, but i lose the accuracy i need. The second one gives the same error. –  Mar 28 '21 at 08:19
  • 1
    its a shame but there is no 64bit `pow` function in GLSL (at least that I know of) – Spektre Mar 28 '21 at 08:44