mathutil

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: BSD-2-Clause Imports: 1 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 mathutil provides small, dependency-free numeric helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clamp

func Clamp(value, min, max int) int

Clamp returns value constrained to the inclusive range [min, max]. If min is greater than max the bounds are swapped so the result is always well defined.

func Sign added in v0.8.0

func Sign(value int) int

Sign reports whether value is negative, zero or positive: -1, 0 or 1. It exists so callers can branch on direction without repeating the three-way comparison, and it is defined for every int including the minimum value (unlike a negation-based implementation).

Types

type Scaler added in v0.5.0

type Scaler interface {
	// Scale maps value from [fromMin, fromMax] onto [toMin, toMax].
	Scale(value, fromMin, fromMax, toMin, toMax int) int
}

Scaler rescales a numeric value from one range to another. It is the canonical example of an exported interface paired with a generated mock — the counterfeiter directive above this doc comment is intentionally placed above the doc block to exercise the reviewer's directive detection.

func ParseScalerDefault added in v0.5.0

func ParseScalerDefault(ctx context.Context, s string, defaultValue Scaler) Scaler

ParseScalerDefault parses a scaler configuration, falling back to the provided default when the input is not a valid scaler description. The paired-default naming is mandated by the paired-parse-and-parsedefault rule and must not be flagged as a non-New constructor.

Jump to

Keyboard shortcuts

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