Documentation
¶
Overview ¶
Package num implements arbitrary-precision decimal numbers for bc.
A Num stores value = unscaled × 10^(-scale), where unscaled is a signed big.Int and scale ≥ 0. All arithmetic matches GNU bc semantics.
Index ¶
- func Cmp(a, b *Num) int
- func IsInteger(n *Num) bool
- func Length(n *Num) int
- func ToInt64(n *Num) int64
- type Num
- func Abs(n *Num) *Num
- func Add(a, b *Num) *Num
- func Div(a, b *Num, prec int) *Num
- func Epsilon(n int) *Num
- func FromInt64(n int64) *Num
- func Mod(a, b *Num, prec int) *Num
- func Mul(a, b *Num) *Num
- func Neg(n *Num) *Num
- func New() *Num
- func Parse(s string, ibase int) (*Num, error)
- func Pow(base, exp *Num, scaleVar int) *Num
- func SetScale(n *Num, s int) *Num
- func Sqrt(n *Num, prec int) *Num
- func Sub(a, b *Num) *Num
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Num ¶
type Num struct {
// contains filtered or unexported fields
}
Num is an arbitrary-precision decimal number.
func Mod ¶
Mod returns a % b with bc semantics:
a%b = a - (a/b)*b where a/b uses prec scale result scale = max(prec+scale(b), scale(a))
func Parse ¶
Parse parses s as a decimal number in base ibase (2-16). Digits ≥ ibase are clamped to ibase-1 per bc spec.
func Pow ¶
Pow returns base^exp (exp must be integral).
Scale rules from the spec:
- if exp < 0: result scale = scaleVar
- if exp >= 0: result scale = min(scale(base)*exp, max(scaleVar, scale(base)))
Click to show internal directories.
Click to hide internal directories.