Documentation ¶
Overview ¶
Package exact implements mathematically exact values and operations for untyped Go constant values.
A special Unknown value may be used when a constant value is unknown due to an error; operations on unknown values produce unknown values.
Index ¶
- func BitLen(x Value) int
- func BoolVal(x Value) bool
- func Bytes(x Value) []byte
- func Compare(x Value, op token.Token, y Value) bool
- func Float64Val(x Value) (float64, bool)
- func Int64Val(x Value) (int64, bool)
- func Sign(x Value) int
- func StringVal(x Value) string
- func Uint64Val(x Value) (uint64, bool)
- type Kind
- type Value
- func BinaryOp(x Value, op token.Token, y Value) Value
- func Denom(x Value) Value
- func Imag(x Value) Value
- func MakeBool(b bool) Value
- func MakeFloat64(x float64) Value
- func MakeFromBytes(bytes []byte) Value
- func MakeFromLiteral(lit string, tok token.Token) Value
- func MakeImag(x Value) Value
- func MakeInt64(x int64) Value
- func MakeString(s string) Value
- func MakeUint64(x uint64) Value
- func MakeUnknown() Value
- func Num(x Value) Value
- func Real(x Value) Value
- func Shift(x Value, op token.Token, s uint) Value
- func UnaryOp(op token.Token, y Value, size int) Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BitLen ¶
BitLen returns the number of bits required to represent the absolute value x in binary representation; x must be an Int or an Unknown. If x is Unknown, the result is 0.
func BoolVal ¶
BoolVal returns the Go boolean value of x, which must be a Bool or an Unknown. If x is Unknown, the result is false.
func Bytes ¶
Bytes returns the bytes for the absolute value of x in little- endian binary representation; x must be an Int.
func Compare ¶
Compare returns the result of the comparison x op y. The comparison must be defined for the operands. If one of the operands is Unknown, the result is false.
func Float64Val ¶
Float64Val returns the nearest Go float64 value of x and whether the result is exact; x must be numeric but not Complex, or Unknown. If x is Unknown, the result is (0, false).
func Int64Val ¶
Int64Val returns the Go int64 value of x and whether the result is exact; x must be an Int or an Unknown. If the result is not exact, its value is undefined. If x is Unknown, the result is (0, false).
func Sign ¶
Sign returns -1, 0, or 1 depending on whether x < 0, x == 0, or x > 0; x must be numeric or Unknown. For complex values x, the sign is 0 if x == 0, otherwise it is != 0. If x is Unknown, the result is 1.
Types ¶
type Value ¶
type Value interface { // Kind returns the value kind; it is always the smallest // kind in which the value can be represented exactly. Kind() Kind // String returns a human-readable form of the value. String() string // contains filtered or unexported methods }
A Value represents a mathematically precise value of a given Kind.
func BinaryOp ¶
BinaryOp returns the result of the binary expression x op y. The operation must be defined for the operands. If one of the operands is Unknown, the result is Unknown. To force integer division of Int operands, use op == token.QUO_ASSIGN instead of token.QUO; the result is guaranteed to be Int in this case. Division by zero leads to a run-time panic.
func Denom ¶
Denom returns the denominator of x; x must be Int, Float, or Unknown. If x is Unknown, the result is Unknown, otherwise it is an Int >= 1.
func Imag ¶
Imag returns the imaginary part of x, which must be a numeric or unknown value. If x is Unknown, the result is Unknown.
func MakeFloat64 ¶
MakeFloat64 returns the numeric value for x. If x is not finite, the result is unknown.
func MakeFromBytes ¶
MakeFromBytes returns the Int value given the bytes of its little-endian binary representation. An empty byte slice argument represents 0.
func MakeFromLiteral ¶
MakeFromLiteral returns the corresponding integer, floating-point, imaginary, character, or string value for a Go literal string. The result is nil if the literal string is invalid.
func MakeImag ¶
MakeImag returns the numeric value x*i (possibly 0); x must be Int, Float, or Unknown. If x is Unknown, the result is Unknown.
func Num ¶
Num returns the numerator of x; x must be Int, Float, or Unknown. If x is Unknown, the result is Unknown, otherwise it is an Int.
func Real ¶
Real returns the real part of x, which must be a numeric or unknown value. If x is Unknown, the result is Unknown.