Documentation
¶
Index ¶
- Variables
- type Real
- func (u *Real) Abs() *Real
- func (u *Real) Acos() (*Real, error)
- func (u *Real) Add(other *Real) *Real
- func (u *Real) Asin() (*Real, error)
- func (u *Real) Atan() *Real
- func (y *Real) Atan2(x *Real) (*Real, error)
- func (u *Real) Cbrt() *Real
- func (u *Real) Ceil(p int) *Real
- func (u *Real) Constructive() constructive.Real
- func (u *Real) Cos() *Real
- func (u *Real) Cosh() *Real
- func (u *Real) Divide(other *Real) *Real
- func (u *Real) Exp() *Real
- func (u *Real) Floor(p int) *Real
- func (u *Real) Format(f fmt.State, c rune)
- func (u *Real) FormattedString(decimalDigits, radix int) string
- func (u *Real) Gamma() (*Real, error)
- func (u *Real) Inverse() *Real
- func (u *Real) IsZero() bool
- func (u *Real) Ln() (*Real, error)
- func (u *Real) Log(base *Real) (*Real, error)
- func (u *Real) Log2() (*Real, error)
- func (u *Real) Log10() (*Real, error)
- func (u *Real) Max(other *Real, p int) *Real
- func (u *Real) Min(other *Real, p int) *Real
- func (u *Real) Multiply(other *Real) *Real
- func (u *Real) Negate() *Real
- func (u *Real) Pow(n *Real) (*Real, error)
- func (u *Real) Round(p int) *Real
- func (u *Real) RoundToEven(p int) *Real
- func (u *Real) ShiftLeft(n int) *Real
- func (u *Real) ShiftRight(n int) *Real
- func (u *Real) Sin() *Real
- func (u *Real) Sinh() *Real
- func (u *Real) Sqrt() (*Real, error)
- func (u *Real) Subtract(other *Real) *Real
- func (u *Real) Tan() *Real
- func (u *Real) Tanh() *Real
Constants ¶
This section is empty.
Variables ¶
var E = sync.OnceValue(func() *Real { return New(constructive.E(), rational.One()) })
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.
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.
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.
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.
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.
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.
var Half = sync.OnceValue(func() *Real { return New(constructive.One(), rational.New64(1, 2)) })
var Lemniscate = sync.OnceValue(func() *Real { return New(constructive.Lemniscate(), rational.One()) })
var Ln2 = sync.OnceValue(func() *Real { return New(constructive.Ln2(), rational.One()) })
var NegativeOne = sync.OnceValue(func() *Real { return New(constructive.One(), rational.New64(-1, 1)) })
var One = sync.OnceValue(func() *Real { return New(constructive.One(), rational.One()) })
var Phi = sync.OnceValue(func() *Real { return New(constructive.Phi(), rational.One()) })
var Pi = sync.OnceValue(func() *Real { return New(constructive.Pi(), rational.One()) })
var PrimeConstant = sync.OnceValue(func() *Real { return New(constructive.PrimeConstant(), rational.One()) })
var Sigma = sync.OnceValue(func() *Real { return New(constructive.Sigma(), rational.One()) })
var Sqrt2 = sync.OnceValue(func() *Real { return New(constructive.Sqrt2(), rational.One()) })
var Ten = sync.OnceValue(func() *Real { return New(constructive.One(), rational.New64(10, 1)) })
var Two = sync.OnceValue(func() *Real { return New(constructive.One(), rational.New64(2, 1)) })
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) Acos ¶
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 ¶
Add adds the current number and another number together, returning a new Real number.
func (*Real) Asin ¶
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) Atan2 ¶
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 ¶
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 ¶
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) Divide ¶
Divide divides the current number by another number, returning a new Real number.
func (*Real) Floor ¶
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) FormattedString ¶
FormattedString returns a string representation of the unified real number with the specified number of decimal digits and radix.
func (*Real) Gamma ¶
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 ¶
Inverse returns the multiplicative inverse of the current number as a new Real number.
func (*Real) IsZero ¶
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 ¶
Ln returns the natural logarithm of u. It requires a positive argument and returns ErrNonPositive otherwise.
func (*Real) Log ¶
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 ¶
Log2 returns the base-2 logarithm of u. It requires a positive argument and returns ErrNonPositive otherwise.
func (*Real) Log10 ¶
Log10 returns the base-10 logarithm of u. It requires a positive argument and returns ErrNonPositive otherwise.
func (*Real) Max ¶
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 ¶
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 ¶
Multiply multiplies the current number by another number, returning a new Real number.
func (*Real) Pow ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) Sqrt ¶
Sqrt returns the square root of u. It requires a non-negative argument and returns ErrNegative otherwise.