Documentation
¶
Index ¶
- Variables
- type Real
- func (u *Real) Add(other *Real) *Real
- func (u *Real) Constructive() constructive.Real
- func (u *Real) Divide(other *Real) *Real
- func (u *Real) Format(f fmt.State, c rune)
- func (u *Real) FormattedString(decimalDigits, radix int) string
- func (u *Real) Inverse() *Real
- func (u *Real) IsZero() bool
- func (u *Real) Multiply(other *Real) *Real
- func (u *Real) Negate() *Real
- func (u *Real) ShiftLeft(n int) *Real
- func (u *Real) ShiftRight(n int) *Real
- func (u *Real) Subtract(other *Real) *Real
Constants ¶
This section is empty.
Variables ¶
var E = sync.OnceValue(func() *Real { return New(constructive.E(), rational.One()) })
var Half = sync.OnceValue(func() *Real { return New(constructive.One(), rational.New64(1, 2)) })
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 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) Add ¶
Add adds the current number and another number together, returning a new Real number.
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) FormattedString ¶
FormattedString returns a string representation of the unified real number with the specified number of decimal digits and radix.
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) Multiply ¶
Multiply multiplies the current number by another number, returning a new Real number.
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.