## gain (`lygia`/`math`/`gain`)

Remapping the unit interval into the unit interval by expanding the sides and compressing the center, and keeping 1/2 mapped to 1/2, that can be done with the gain() function. From https://iquilezles.org/articles/functions/

Use:

``````<float> gain(<float> x, <float> k)
``````

Check it on Github

``````
#ifndef FNC_GAIN
#define FNC_GAIN
float gain(float x, float k) {
float a = 0.5 * pow(2.0*((x<0.5)? x : 1.0-x), k);
return (x < 0.5) ? a : 1.0-a;
}
#endif
``````

Use:

``````<float> gain(<float> x, <float> k)
``````

Check it on Github

``````
#ifndef FNC_GAIN
#define FNC_GAIN
float gain(float x, float k) {
const float a = 0.5*pow(2.0*((x<0.5)?x:1.0-x), k);
return (x<0.5)?a:1.0-a;
}
#endif
``````

Check it on Github

``````
fn gain(x: f32, k: f32) -> f32 {
let a = 0.5 * pow(2.0 * select(1.0-x, x, x<0.5), k);
return select(1.0-a, a, x<0.5);
}
``````

Dependencies:

Use:

``````<float> gain(<float> x, <float> k)
``````

Check it on Github

``````

#ifndef FNC_GAIN
#define FNC_GAIN
inline __host__ __device__ float gain(float x, float k) {
const float a = 0.5f * pow(2.0f * ((x < 0.5f)? x : 1.0f - x), k);
return (x < 0.5f)? a : 1.0f - a;
}
#endif
``````