# shz_powif

Source: https://sh4zam.com/api/scalar/shz_powif/

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

```c
SHZ_INLINE float shz_powif(float x, int n) SHZ_NOEXCEPT;
```

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

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `x` | `float` |  |
| `n` | `int` |  |

## Returns

`float`

## Details

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.

## Notes

- [`shz_powif`](https://sh4zam.com/api/scalar/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().

## Availability

- **C++ equivalent:** [`shz::powif`](https://sh4zam.com/api/cpp/#shzpowif)
- **Type-generic form:** none
- **Back-ends:** SH4: dedicated SH4 implementation · SW: portable C · SPU: shared C implementation
- **Defined in:** [`sh4zam/shz_scalar.h:437`](https://github.com/gyrovorbis/sh4zam/blob/6b22b851ad9ca109049f956dbbbecf7c519c959f/include/sh4zam/shz_scalar.h#L437)
- **Module:** [Scalar](https://sh4zam.com/api/scalar/), section "Transcendental"

## See also

[`shz_powf`](https://sh4zam.com/api/scalar/shz_powf/)
