arithmetic

package
v3.0.0-rc62 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 5 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 arithmetic evaluates the arithmetic a configuration keyword holds, so a size can be written as a share of another size rather than as a number somebody worked out by hand.

size = $(50% * {disk#vg.capacity})
size = $({DEFAULT.size} / 2)
size = $({disk#vg.capacity} - 10g)

The references are resolved before this is asked anything, so what it reads is arithmetic over numbers. A number is written the way every other size in a configuration is written, so "10g" and "10GB" are sizes here too.

The operators are "+", "-", "*", "/", "//" and "%". The last two are the integer division and the remainder of it, so "5//2" is 2 and "5%2" is 1.

A percent sign is also how a share is written, "50%" being a half, and the two are told apart by what follows the sign: a number opens the right side of a remainder, and anything else ends a share. So "50% * 10g" is half of ten gibibytes, and "50 % 2" is what is left of fifty when divided by two.

Index

Constants

View Source
const Open = "$("

Open is what introduces an expression, and is looked for before anything else is done, so a value holding none is not parsed at all.

Variables

This section is empty.

Functions

func Eval

func Eval(s string) (string, error)

Eval replaces every expression in s by the number it computes, and leaves the rest of s alone.

func EvalExpr

func EvalExpr(s string) (int64, error)

EvalExpr computes one expression, written without the "$(" and ")" around it.

The arithmetic is done in floating point and the answer rounded, because a share of a size is a fraction and the caller is asking for a count of bytes: a half of an odd number of them is one of them or the other, not an error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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