unified

package
v0.0.0-...-5f9c134 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var E = sync.OnceValue(func() *Real {
	return New(constructive.E(), rational.One())
})
View Source
var ErrGammaPole = errors.New("argument must not be a non-positive integer")

ErrGammaPole indicates that gamma was called at one of its poles, the non-positive integers, where the function is undefined.

View Source
var ErrInvalidBase = errors.New("base must not be equal to one")

ErrInvalidBase indicates a logarithm base that is positive but equal to one, for which the logarithm is undefined.

View Source
var ErrNegative = errors.New("argument must be non-negative")

ErrNegative ndicates that a function requires a non-negative argument, such as the radicand of a square root.

View Source
var ErrNonPositive = errors.New("argument must be positive")

ErrNonPositive indicates thata function requires a strictly positive argument, such as the argument of a logarithm or the base of a power with a non-integer exponent.

View Source
var ErrOutsideUnitInterval = errors.New("argument must be in [-1, 1]")

ErrOutsideUnitInterval indicates that a function requires an argument in [-1, 1], such as the argument of arcsine or arccosine.

View Source
var ErrUndefinedAtOrigin = errors.New("atan2 is undefined at the origin")

ErrUndefinedAtOrigin indicates that atan2 was called with both arguments zero, where the angle is undefined.

View Source
var Half = sync.OnceValue(func() *Real {
	return New(constructive.One(), rational.New64(1, 2))
})
View Source
var Lemniscate = sync.OnceValue(func() *Real {
	return New(constructive.Lemniscate(), rational.One())
})
View Source
var Ln2 = sync.OnceValue(func() *Real {
	return New(constructive.Ln2(), rational.One())
})
View Source
var NegativeOne = sync.OnceValue(func() *Real {
	return New(constructive.One(), rational.New64(-1, 1))
})
View Source
var One = sync.OnceValue(func() *Real {
	return New(constructive.One(), rational.One())
})
View Source
var Phi = sync.OnceValue(func() *Real {
	return New(constructive.Phi(), rational.One())
})
View Source
var Pi = sync.OnceValue(func() *Real {
	return New(constructive.Pi(), rational.One())
})
View Source
var PrimeConstant = sync.OnceValue(func() *Real {
	return New(constructive.PrimeConstant(), rational.One())
})
View Source
var Sigma = sync.OnceValue(func() *Real {
	return New(constructive.Sigma(), rational.One())
})
View Source
var Sqrt2 = sync.OnceValue(func() *Real {
	return New(constructive.Sqrt2(), rational.One())
})
View Source
var Ten = sync.OnceValue(func() *Real {
	return New(constructive.One(), rational.New64(10, 1))
})
View Source
var Two = sync.OnceValue(func() *Real {
	return New(constructive.One(), rational.New64(2, 1))
})
View Source
var Zero = sync.OnceValue(func() *Real {
	return New(constructive.One(), rational.Zero())
})

Functions

This section is empty.

Types

type Real

type Real struct {
	// contains filtered or unexported fields
}

Real represents a real number as a unification of a constructive real and a rational number.

func New

func New(cr constructive.Real, rr *rational.Number) *Real

New creates a new Real number from the given constructive real and rational number. The actual value being represented is `cr * rr`; if either argument is nil, it defaults to one.

func (*Real) Abs

func (u *Real) Abs() *Real

Abs returns the absolute value of u.

func (*Real) Acos

func (u *Real) Acos() (*Real, error)

Acos returns the arccosine of u, in radians, as π/2 - asin(u). It requires an argument in [-1, 1] and returns ErrOutsideUnitInterval otherwise.

func (*Real) Add

func (u *Real) Add(other *Real) *Real

Add adds the current number and another number together, returning a new Real number.

func (*Real) Asin

func (u *Real) Asin() (*Real, error)

Asin returns the arcsine of u, in radians. It requires an argument in [-1, 1] and returns ErrOutsideUnitInterval otherwise. The endpoints ±1 are special-cased to ±π/2, where the derived form atan(x / sqrt(1 - x²)) would divide by zero. Endpoint detection is structural and so recognizes only the rational ±1, since constructive reals cannot decide equality in general.

func (*Real) Atan

func (u *Real) Atan() *Real

Atan returns the arctangent of u, in radians. It is total.

func (*Real) Atan2

func (y *Real) Atan2(x *Real) (*Real, error)

Atan2 returns the angle, in radians, of the point (x, y) measured from the positive x-axis, where the receiver is y. The result lies in (-π, π]. Both arguments zero returns ErrUndefinedAtOrigin.

func (*Real) Cbrt

func (u *Real) Cbrt() *Real

Cbrt returns the real cube root of u. It is total: it accepts negative input, so Cbrt(-8) is -2, and Cbrt(0) is 0. The cube root of a negative value is computed by sign extraction over Pow(|u|, 1/3), keeping the result real.

func (*Real) Ceil

func (u *Real) Ceil(p int) *Real

Ceil returns the least integer greater than or equal to u. A purely rational value is ceiled exactly; otherwise the boundary is decided at precision p.

func (*Real) Constructive

func (u *Real) Constructive() constructive.Real

Constructive returns the constructive real representation of the unified real number.

func (*Real) Cos

func (u *Real) Cos() *Real

Cos returns the cosine of u, in radians.

func (*Real) Cosh

func (u *Real) Cosh() *Real

Cosh returns the hyperbolic cosine of u.

func (*Real) Divide

func (u *Real) Divide(other *Real) *Real

Divide divides the current number by another number, returning a new Real number.

func (*Real) Exp

func (u *Real) Exp() *Real

Exp returns e raised to the power of u.

func (*Real) Floor

func (u *Real) Floor(p int) *Real

Floor returns the greatest integer less than or equal to u. A purely rational value is floored exactly; otherwise the boundary is decided at precision p.

func (*Real) Format

func (u *Real) Format(f fmt.State, c rune)

Format implements the fmt.Formatter interface for custom formatting.

func (*Real) FormattedString

func (u *Real) FormattedString(decimalDigits, radix int) string

FormattedString returns a string representation of the unified real number with the specified number of decimal digits and radix.

func (*Real) Gamma

func (u *Real) Gamma() (*Real, error)

Gamma returns the gamma function Γ(u). It is undefined at the non-positive integers, its poles, and returns ErrGammaPole there. Detection is structural: it recognizes only an exact non-positive integer on the rational representation, since constructive reals cannot decide equality in general. A near-pole irrational argument is finite and computes to a large value.

func (*Real) Inverse

func (u *Real) Inverse() *Real

Inverse returns the multiplicative inverse of the current number as a new Real number.

func (*Real) IsZero

func (u *Real) IsZero() bool

IsZero returns true if the current number is zero. In order for the number to be zero, the rational component must be zero. The constructive component cannot be used to determine if the number is zero, since constructive reals can only approximate zero at a specific precision (unless it's the zero object).

func (*Real) Ln

func (u *Real) Ln() (*Real, error)

Ln returns the natural logarithm of u. It requires a positive argument and returns ErrNonPositive otherwise.

func (*Real) Log

func (u *Real) Log(base *Real) (*Real, error)

Log returns the logarithm of u in the given base. It requires a positive argument and a positive base; a non-positive argument or base returns ErrNonPositive, and a base of one returns ErrInvalidBase.

func (*Real) Log2

func (u *Real) Log2() (*Real, error)

Log2 returns the base-2 logarithm of u. It requires a positive argument and returns ErrNonPositive otherwise.

func (*Real) Log10

func (u *Real) Log10() (*Real, error)

Log10 returns the base-10 logarithm of u. It requires a positive argument and returns ErrNonPositive otherwise.

func (*Real) Max

func (u *Real) Max(other *Real, p int) *Real

Max returns the greater of u and other. When both are purely rational the comparison is exact; otherwise it is decided at precision p with PreciseCmp, so operands equal within p may return either operand.

func (*Real) Min

func (u *Real) Min(other *Real, p int) *Real

Min returns the lesser of u and other. When both are purely rational the comparison is exact; otherwise it is decided at precision p with PreciseCmp, so operands equal within p may return either operand.

func (*Real) Multiply

func (u *Real) Multiply(other *Real) *Real

Multiply multiplies the current number by another number, returning a new Real number.

func (*Real) Negate

func (u *Real) Negate() *Real

Negate returns the negation of the current number as a new Real number.

func (*Real) Pow

func (u *Real) Pow(n *Real) (*Real, error)

Pow returns u raised to the power n.

An integer exponent is honored over any base via sign-aware repeated multiplication. A non-integer exponent requires a positive base and returns ErrNonPositive otherwise. The base zero is handled explicitly:

- `Pow(0, k)` is 0 for positive k. - `Pow(0, 0)` is 1 - A negative or non-integer exponent over a zero base returns ErrNonPositive.

func (*Real) Round

func (u *Real) Round(p int) *Real

Round returns the nearest integer to u, rounding half away from zero. A purely rational value is rounded exactly; otherwise the boundary is decided at precision p, where an exact halfway tie is not finitely decidable.

func (*Real) RoundToEven

func (u *Real) RoundToEven(p int) *Real

RoundToEven returns the nearest integer to u, rounding ties to even. A purely rational value is rounded exactly; otherwise the boundary is decided at precision p, where an exact halfway tie is not finitely decidable.

func (*Real) ShiftLeft

func (u *Real) ShiftLeft(n int) *Real

ShiftLeft shifts the number to the left by the specified number of bits, which is equivalent to multiplying the number by 2^n.

func (*Real) ShiftRight

func (u *Real) ShiftRight(n int) *Real

ShiftRight shifts the number to the right by the specified number of bits, which is equivalent to dividing the number by 2^n.

func (*Real) Sin

func (u *Real) Sin() *Real

Sin returns the sine of u, in radians.

func (*Real) Sinh

func (u *Real) Sinh() *Real

Sinh returns the hyperbolic sine of u.

func (*Real) Sqrt

func (u *Real) Sqrt() (*Real, error)

Sqrt returns the square root of u. It requires a non-negative argument and returns ErrNegative otherwise.

func (*Real) Subtract

func (u *Real) Subtract(other *Real) *Real

Subtract `other` from the current number, returning a new Real number.

func (*Real) Tan

func (u *Real) Tan() *Real

Tan returns the tangent of u, in radians.

func (*Real) Tanh

func (u *Real) Tanh() *Real

Tanh returns the hyperbolic tangent of u.

Jump to

Keyboard shortcuts

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