util

package
v0.2.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: BSD-3-Clause Imports: 0 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package util provides small, dependency-free helpers shared across the gopus codec packages. It holds only generic primitives (such as integer/float absolute value) that are too trivial to belong to a specific codec stage and that several packages would otherwise duplicate.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[T Signed](x T) T

Abs returns the absolute value of x, mirroring libopus' integer abs() and silk_abs_int* / the fabsf() used in the FLP paths.

The width is preserved by the type parameter: |x| is computed as -x in the same type as x, so it carries libopus' two's-complement wraparound exactly. For the most-negative value of a signed integer type (e.g. math.MinInt16), -x is unrepresentable and wraps back to that same negative value, which is the identical behaviour of the C unary minus libopus relies on. Callers that need a saturating absolute value must clamp before calling Abs.

Types

type Signed

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~float32 | ~float64
}

Signed constrains the type parameter of Abs to the signed integer and floating-point kinds gopus operates on. It deliberately matches the width set libopus uses internally (signed char / opus_int8, opus_int16, opus_int32, opus_int64, plus the float and double sample types), so a single Abs call reproduces the C operand width at every call site.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL