Skip to content

shz_powif

Markdown
SHZ_INLINE float shz_powif(float x, int n) SHZ_NOEXCEPT;

Raises x to the integer power n, using exponentiation by squaring.

NameTypeDescription
xfloat
nint

float

Unlike shz_powf(), this is not an approximation: the result is computed by repeated multiplication, taking popcount(|n|) + floor(log2(|n|)) multiplies, plus a single division by x when n is negative.

When n is a compile-time constant, this expands to GCC's optimal multiplication chain for that exponent instead.

  • shz_powif(x, 0) returns 1.0f for every x, including 0.0f.
  • Rounding may differ slightly from multiplying x by itself n times, or from powf().
  • C++ equivalent: shz::powif
  • Type-generic form: none
  • Back-ends: SH4: dedicated SH4 implementation · SW: portable C · SPU: shared C implementation
  • Defined in: sh4zam/shz_scalar.h:437
  • Module: Scalar, section "Transcendental"

shz_powf