Documentation
¶
Overview ¶
Copyright Consensys Software Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Copyright Consensys Software Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Copyright Consensys Software Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Copyright Consensys Software Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Index ¶
- Variables
- func NegPow2(n uint) *big.Int
- func NextPowerOfTwo(n uint) uint
- func Pow2(n uint) *big.Int
- func PowUint64(base uint64, exp uint64) uint64
- func Sum[T uint8 | uint16 | uint32 | uint64 | uint | int8 | int16 | int32 | int64 | int](items ...T) T
- type InfInt
- func (p *InfInt) Add(other InfInt) InfInt
- func (p *InfInt) Cmp(o InfInt) int
- func (p *InfInt) CmpInt(other big.Int) int
- func (p *InfInt) IntVal() big.Int
- func (p *InfInt) IsNotAnInfinity() bool
- func (p *InfInt) Max(o InfInt) InfInt
- func (p *InfInt) Min(o InfInt) InfInt
- func (p *InfInt) Mul(o InfInt) InfInt
- func (p *InfInt) Negate() InfInt
- func (p *InfInt) Set(other InfInt)
- func (p *InfInt) SetInt(other big.Int)
- func (p *InfInt) Sign() int
- func (p *InfInt) String() string
- func (p *InfInt) Sub(other InfInt) InfInt
- type Interval
- func (p *Interval) Add(q Interval)
- func (p *Interval) BitWidth() (width uint, signed bool)
- func (p *Interval) Constant() *big.Int
- func (p *Interval) Contains(val big.Int) bool
- func (p *Interval) Exp(pow uint)
- func (p *Interval) Insert(val Interval)
- func (p *Interval) IsFinite() bool
- func (p *Interval) IsInfinite() bool
- func (p *Interval) MaxIntValue() big.Int
- func (p *Interval) MaxValue() InfInt
- func (p *Interval) MinIntValue() big.Int
- func (p *Interval) MinValue() InfInt
- func (p *Interval) Mul(q Interval)
- func (p *Interval) Set(val Interval)
- func (p *Interval) String() string
- func (p *Interval) Sub(q Interval)
- func (p *Interval) Union(other Interval) Interval
- func (p *Interval) Within(val Interval) bool
Constants ¶
This section is empty.
Variables ¶
var Infinity = InfInt{big.Int{}, infinity}
Infinity represents plain infinity
var NegInfinity = InfInt{big.Int{}, negativeInfinity}
NegInfinity represents negative infinity
var PosInfinity = InfInt{big.Int{}, positiveInfinity}
PosInfinity represents positive infinity
Functions ¶
func NextPowerOfTwo ¶ added in v1.2.21
NextPowerOfTwo returns the smallest power of two greater than or equal to n, treating zero as one.
Types ¶
type InfInt ¶
type InfInt struct {
// contains filtered or unexported fields
}
InfInt represents an unbound (i.e. big) integer value which can, additionally, be either negative infinity, positive infinity or just infinity (i.e. which covers all negative and positive values).
func (*InfInt) Cmp ¶
Cmp performs a comparison of two (potentially infinite) integer values. This will panic if either value is plain infinity.
func (*InfInt) CmpInt ¶
CmpInt compares a potentially infinite integer value against a finite integer value. This will panic if the first value is plain infinity.
func (*InfInt) IntVal ¶
IntVal converts a potentially infinite integer into a finite value. This will panic if this value is an infinity.
func (*InfInt) IsNotAnInfinity ¶
IsNotAnInfinity returns true if this represents a finite integer value.
func (*InfInt) Max ¶
Max determines the greatest of two values. Note the semantics here are odd, as the maximum of plain infinity and anything is positive infinity!
func (*InfInt) Min ¶
Min determines the least of two values. Note the semantics here are odd, as the minimum of plain infinity and anything is negative infinity!
func (*InfInt) Mul ¶
Mul multiplies a (potentially infinite) value against this (potentially infinite) value. If either operand is an infinity, then some kind of infinity is always returned.
func (*InfInt) Set ¶
Set this to match some (potentially infinite) integer. Observe this will clone the underlying big integer if the value is finite.
func (*InfInt) SetInt ¶
SetInt sets this to match a big integer. Observe this will clone the underlying big integer.
type Interval ¶
type Interval struct {
// contains filtered or unexported fields
}
Interval provides a discrete range of integers, such as 0..1, 1..18, etc. An interval can be used to approximate the possible values that a given expression could evaluate to. An interval can additionally represent three different forms of infinity: negative infinity, positive infinity and plain infinity. The latter contains both negative and positive infinities. For more information on this system, see the following paper:
Integer Range Analysis for Whiley on Embedded Systems, David J. Pearce. In Proceedings of the IEEE/IFIP Workshop on Software Technologies for Future Embedded and Ubiquitous Systems (SEUS), pages 26--33, 2015.
var INFINITY Interval = Interval{NegInfinity, PosInfinity}
INFINITY represents the interval which encloses all other intervals.
func NewInterval ¶
NewInterval creates an interval representing a given range.
func NewInterval64 ¶
NewInterval64 creates an interval representing a given range.
func (*Interval) BitWidth ¶
BitWidth returns the minimum number of bits required to store all elements in this interval. Observe that, if the interval can contain negative numbers then it is considered to be "signed", and the bitwidth returned the maximum of either the positive or negative sides. Note: this method will panic if called with the infinite interval.
func (*Interval) Constant ¶
Constant checks whether this interval represents a constant value and, if so, returns it. Otherwise, it returns nil.
func (*Interval) IsFinite ¶
IsFinite determines whether or not this interval represents an a finite value (i.e. not an infinity).
func (*Interval) IsInfinite ¶
IsInfinite determines whether or not this interval represents an infinity.
func (*Interval) MaxIntValue ¶
MaxIntValue returns the maximum value that this interval includes. Note this will panic if the interval is infinite.
func (*Interval) MinIntValue ¶
MinIntValue returns the minimum value that this interval includes. Note this will panic if the interval is infinite.
func (*Interval) Set ¶
Set assigns a given value to this interval. Note: this method will panic if called with the infinite interval.