How to calculate sinh, cosh, tanh in spark sl?

is there any alternatives to calculate sinh, cosh, tanh?
seems like spark sl doesn’t support these
https://registry.khronos.org/OpenGL-Refpages/gl4/html/tanh.xhtml

If you look oat those docs, they give you the formulae for those functions.

https://registry.khronos.org/OpenGL-Refpages/gl4/html/sinh.xhtml

sinh(x) = (pow(e, x) - pow(e, -x)) / 2.0

https://registry.khronos.org/OpenGL-Refpages/gl4/html/cosh.xhtml

cosh(x) = (pow(e, x) + pow(e, -x)) / 2.0

And then once you have those functions, you can use them to get tanh.

tanh(x) = sinh(x) / cosh(x)

shader.sca (5.4 KB)

Thank you so much for taking your time answering to our questions dear Mr Beckwith
I already tried this solution but got really weird and unexpected result.
if i declare “tanh” as a float, i have to put * in the equations at this will ruin the whole code or maybe i shouldn’t have to do that at all.
if it was possible for you i’ll be really greatful that you take a look at this shader code. line 10 through 18

Well, there’s something else wrong with this shader, and it generally doesn’t run well in Spark, but here you go :slight_smile:

You need to define sinh, cosh, tanh as functions, not values. They take an input and give an output.

float sinh(float x) {
    return (pow(e, x) - pow(e, -x)) / 2.0;
}
float cosh (float x){
    return (pow(e, x) + pow(e, -x)) / 2.0;
}
float tanh(float x){
    return sinh(x) / cosh(x);
}
float box (in float x, in float x1, in float x2, in float a, in float b)
{
     float pon = tanh(a * (x - x1)) + tanh(-b * (x - x2));
	 return pon;
}
1 Like

Thank you at least I learned something new because of you :yellow_heart:

1 Like