mathutil

package
v0.35.21 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Unlicense Imports: 1 Imported by: 22 modules, 20 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 contains generic helpers for common algorithms and mathematic operations.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolToNumber

func BoolToNumber[T Number](cond bool) (res T)

BoolToNumber returns 1 if cond is true and 0 otherwise.

Example
package main

import (
	"fmt"

	"github.com/AdguardTeam/golibs/mathutil"
)

func main() {
	fmt.Println(mathutil.BoolToNumber[int](true))
	fmt.Println(mathutil.BoolToNumber[int](false))

	type flag float64
	fmt.Println(mathutil.BoolToNumber[flag](true))
	fmt.Println(mathutil.BoolToNumber[flag](false))

}
Output:
1
0
1
0

Types

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

Number is a type constraint for all numbers.

Directories

Path Synopsis
Package randutil contains utilities for random numbers.
Package randutil contains utilities for random numbers.

Jump to

Keyboard shortcuts

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