Source: https://developer.android.com/guide/topics/renderscript/reference/rs_math?hl=fr
Timestamp: 2019-04-25 12:40:15+00:00

Document:
The mathematical functions below can be applied to scalars and vectors. When applied to vectors, the returned value is a vector of the function applied to each entry of the input.
See Vector Math Functions for functions like distance() and length() that interpret instead the input as a single vector in n-dimensional space.
The precision of the mathematical operations on 32 bit floats is affected by the pragmas rs_fp_relaxed and rs_fp_full. Under rs_fp_relaxed, subnormal values may be flushed to zero and rounding may be done towards zero. In comparison, rs_fp_full requires correct handling of subnormal values, i.e. smaller than 1.17549435e-38f. rs_fp_rull also requires round to nearest with ties to even.
half_: May perform internal computations using 16 bit floats. Additionally, subnormal values may be flushed to zero, and rounding towards zero may be used.
The inverse of pi, as a 32 bit float.
2 divided by pi, as a 32 bit float.
2 divided by the square root of pi, as a 32 bit float.
The number e, the base of the natural logarithm, as a 32 bit float.
The natural logarithm of 10, as a 32 bit float.
The natural logarithm of 2, as a 32 bit float.
The logarithm base 10 of e, as a 32 bit float.
The logarithm base 2 of e, as a 32 bit float.
The constant pi, as a 32 bit float.
Pi divided by 2, as a 32 bit float.
Pi divided by 4, as a 32 bit float.
The inverse of the square root of 2, as a 32 bit float.
The square root of 2, as a 32 bit float.
Returns the absolute value of an integer.
Returns the inverse cosine, in radians.
Returns the inverse hyperbolic cosine, in radians.
Returns the inverse cosine in radians, divided by pi.
To get an inverse cosine measured in degrees, use acospi(a) * 180.f.
Returns the inverse sine, in radians.
Returns the inverse hyperbolic sine, in radians.
Returns the inverse sine in radians, divided by pi.
To get an inverse sine measured in degrees, use asinpi(a) * 180.f.
Returns the inverse tangent, in radians.
Returns the inverse tangent of (numerator / denominator), in radians.
Returns the inverse tangent of (numerator / denominator), in radians, divided by pi.
To get an inverse tangent measured in degrees, use atan2pi(n, d) * 180.f.
Returns the inverse hyperbolic tangent, in radians.
Returns the inverse tangent in radians, divided by pi.
To get an inverse tangent measured in degrees, use atanpi(a) * 180.f.
Returns the smallest integer not less than a value.
For example, ceil(1.2f) returns 2.f, and ceil(-1.2f) returns -1.f.
Lower bound, a scalar or matching vector.
High bound, must match the type of low.
Clamps a value to a specified high and low bound. clamp() returns min_value if value < min_value, max_value if value > max_value, otherwise value.
There are two variants of clamp: one where the min and max are scalars applied to all entries of the value, the other where the min and max are also vectors.
If min_value is greater than max_value, the results are undefined.
Returns the number of leading 0-bits in a value.
For example, clz((char)0x03) returns 6.
Copies the sign from sign_value to magnitude_value.
The value returned is either magnitude_value or -magnitude_value.
For example, copysign(4.0f, -2.7f) returns -4.0f and copysign(-4.0f, 2.7f) returns 4.0f.
Returns the cosine of an angle measured in radians.
Returns the hypebolic cosine of v, where v is measured in radians.
Returns the cosine of (v * pi), where (v * pi) is measured in radians.
To get the cosine of a value measured in degrees, call cospi(v / 180.f).
Returns the complementary error function.
Returns e raised to v, i.e. e ^ v.
Returns 10 raised to v, i.e. 10.f ^ v.
Returns 2 raised to v, i.e. 2.f ^ v.
Returns e raised to v minus 1, i.e. (e ^ v) - 1.
Returns the absolute value of the float v.
Returns the positive difference between two values.
If a > b, returns (a - b) otherwise returns 0f.
Returns the smallest integer not greater than a value.
For example, floor(1.2f) returns 1.f, and floor(-1.2f) returns -2.f.
Multiply and add. Returns (multiplicand1 * multiplicand2) + offset.
This function is similar to mad(). fma() retains full precision of the multiplied result and rounds only after the addition. mad() rounds after the multiplication and the addition. This extra precision is not guaranteed in rs_fp_relaxed mode.
Returns the maximum of a and b, i.e. (a < b ? b : a).
The max() function returns identical results but can be applied to more data types.
Returns the minimum of a and b, i.e. (a > b ? b : a).
The min() function returns identical results but can be applied to more data types.
Returns the remainder of (numerator / denominator), where the quotient is rounded towards zero.
The function remainder() is similar but rounds toward the closest integer. For example, fmod(-3.8f, 2.f) returns -1.8f (-3.8f - -1.f * 2.f) while remainder(-3.8f, 2.f) returns 0.2f (-3.8f - -2.f * 2.f).
If floor is not null, *floor will be set to the floor of v.
Returns the positive fractional part of v, i.e. v - floor(v).
For example, fract(1.3f, &val) returns 0.3f and sets val to 1.f. fract(-1.3f, &val) returns 0.7f and sets val to -2.f.
If exponent is not null, *exponent will be set to the exponent of v.
Returns the binary mantissa and exponent of v, i.e. v == mantissa * 2 ^ exponent.
The mantissa is always between 0.5 (inclusive) and 1.0 (exclusive).
See ldexp() for the reverse operation. See also logb() and ilogb().
Returns the approximate reciprocal of a value.
The precision is that of a 16 bit floating point value.
Returns the approximate value of (1.f / sqrt(value)).
Returns the approximate square root of a value.
Returns the hypotenuse, i.e. sqrt(a * a + b * b).
Returns the base two exponent of a value, where the mantissa is between 1.f (inclusive) and 2.f (exclusive).
For example, ilogb(8.5f) returns 3.
Because of the difference in mantissa, this number is one less than is returned by frexp().
logb() is similar but returns a float.
Exponent, a single component or matching vector.
Returns the floating point created from the mantissa and exponent, i.e. (mantissa * 2 ^ exponent).
See frexp() for the reverse operation.
If sign_of_gamma is not null, *sign_of_gamma will be set to -1.f if the gamma of v is negative, otherwise to 1.f.
Returns the natural logarithm of the absolute value of the gamma function, i.e. log(fabs(tgamma(v))).
Returns the base 10 logarithm.
Returns the natural logarithm of (v + 1.f).
Returns the base 2 logarithm.
For example, logb(8.5f) returns 3.f.
ilogb() is similar but returns an integer.
This function is similar to fma(). fma() retains full precision of the multiplied result and rounds only after the addition. mad() rounds after the multiplication and the addition. In rs_fp_relaxed mode, mad() may not do the rounding after multiplicaiton.
Returns the maximum value of two arguments.
Returns the minimum value of two arguments.
Returns start + ((stop - start) * fraction).
This can be useful for mixing two values. For example, to create a new color that is 40% color1 and 60% color2, use mix(color1, color2, 0.6f).
*integral_part will be set to the integral portion of the number.
Floating point portion of the value.
Returns the integral and fractional components of a number.
Both components will have the same sign as x. For example, for an input of -3.72f, *integral_part will be set to -3.f and .72f will be returned.
Returns a NaN value (Not a Number).
Returns a half-precision floating point NaN value (Not a Number).
Returns the approximate inverse cosine, in radians.
This function yields undefined results from input values less than -1 or greater than 1.
Returns the approximate inverse hyperbolic cosine, in radians.
Returns the approximate inverse cosine in radians, divided by pi.
Returns the approximate inverse sine, in radians.
Returns the approximate inverse hyperbolic sine, in radians.
Returns the approximate inverse sine in radians, divided by pi.
Returns the approximate inverse tangent, in radians.
Returns the approximate inverse tangent of (numerator / denominator), in radians.
Returns the approximate inverse tangent of (numerator / denominator), in radians, divided by pi.
Returns the approximate inverse hyperbolic tangent, in radians.
Returns the approximate inverse tangent in radians, divided by pi.
Returns the approximate cubic root.
Returns the approximate cosine of an angle measured in radians.
Returns the approximate hypebolic cosine.
Returns the approximate cosine of (v * pi), where (v * pi) is measured in radians.
Computes the approximate division of two values.
It is valid for inputs from -86.f to 86.f. The precision is no worse than what would be expected from using 16 bit floating point values.
It is valid for inputs from -37.f to 37.f. The precision is no worse than what would be expected from using 16 bit floating point values.
It is valid for inputs from -125.f to 125.f. The precision is no worse than what would be expected from using 16 bit floating point values.
Returns the approximate (e ^ v) - 1.
It is not accurate for values very close to zero.
Must be between 0.f and 256.f. The function is not accurate for values very close to zero.
Must be between -15.f and 15.f.
Fast approximate (base ^ exponent).
Returns the approximate approximate reciprocal of a value.
Compute the approximate Nth root of a value.
Returns approximate (1 / sqrt(v)).
Returns the approximate sine of an angle measured in radians.
*cos will be set to the cosine value.
Returns the approximate sine and cosine of a value.
Returns the approximate hyperbolic sine of a value specified in radians.
Returns the approximate sine of (v * pi), where (v * pi) is measured in radians.
To get the sine of a value measured in degrees, call sinpi(v / 180.f).
Returns the approximate tangent of an angle measured in radians.
Returns the approximate hyperbolic tangent of a value.
Returns the approximate tangent of (v * pi), where (v * pi) is measured in radians.
To get the tangent of a value measured in degrees, call tanpi(v / 180.f).
Returns the next representable floating point number from v towards target.
In rs_fp_relaxed mode, a denormalized input value may not yield the next denormalized value, as support of denormalized values is optional in relaxed mode.
Returns base raised to the power exponent, i.e. base ^ exponent.
pown() and powr() are similar. pown() takes an integer exponent. powr() assumes the base to be non-negative.
pow() and powr() are similar. The both take a float exponent. powr() also assumes the base to be non-negative.
Returns base raised to the power exponent, i.e. base ^ exponent. base must be >= 0.
pow() and pown() are similar. They both make no assumptions about the base. pow() takes a float exponent while pown() take an integer.
Returns the remainder of (numerator / denominator), where the quotient is rounded towards the nearest integer.
The function fmod() is similar but rounds toward the closest integer. For example, fmod(-3.8f, 2.f) returns -1.8f (-3.8f - -1.f * 2.f) while remainder(-3.8f, 2.f) returns 0.2f (-3.8f - -2.f * 2.f).
*quotient will be set to the integer quotient.
Remainder, precise only for the low three bits.
Returns the quotient and the remainder of (numerator / denominator).
Only the sign and lowest three bits of the quotient are guaranteed to be accurate.
This function is useful for implementing periodic functions. The low three bits of the quotient gives the quadrant and the remainder the distance within the quadrant. For example, an implementation of sin(x) could call remquo(x, PI / 2.f, &quadrant) to reduce very large value of x to something within a limited range.
Example: remquo(-23.5f, 8.f, &quot) sets the lowest three bits of quot to 3 and the sign negative. It returns 0.5f.
Rounds to the nearest integral value.
rint() rounds half values to even. For example, rint(0.5f) returns 0.f and rint(1.5f) returns 2.f. Similarly, rint(-0.5f) returns -0.f and rint(-1.5f) returns -2.f.
round() is similar but rounds away from zero. trunc() truncates the decimal fraction.
Compute the Nth root of a value.
round() rounds half values away from zero. For example, round(0.5f) returns 1.f and round(1.5f) returns 2.f. Similarly, round(-0.5f) returns -1.f and round(-1.5f) returns -2.f.
rint() is similar but rounds half values toward even. trunc() truncates the decimal fraction.
Clamp a value between low and high.
Return a random value between 0 (or min_value) and max_malue.
Returns the sign of a value.
Returns the sine of an angle measured in radians.
Returns the sine and cosine of a value.
Returns the hyperbolic sine of v, where v is measured in radians.
Returns the sine of (v * pi), where (v * pi) is measured in radians.
Returns 0.f if v < edge, 1.f otherwise.
This can be useful to create conditional computations without using loops and branching instructions. For example, instead of computing (a[i] < b[i]) ? 0.f : atan2(a[i], b[i]) for the corresponding elements of a vector, you could instead use step(a, b) * atan2(a, b).
Returns the tangent of an angle measured in radians.
Returns the tangent of (v * pi), where (v * pi) is measured in radians.
Returns the gamma function of a value.
Rounds to integral using truncation.
For example, trunc(1.7f) returns 1.f and trunc(-1.7f) returns -1.f.
See rint() and round() for other rounding options.

References: v.

 v.

 v.

 v.

 v.

 v.