Documentation ¶
Overview ¶
Package number provides a number abstraction for instruments that either support int64 or float64 input values.
This package is currently in a pre-GA phase. Backwards incompatible changes may be introduced in subsequent minor version releases as we work to track the evolving OpenTelemetry specification and user feedback.
Index ¶
- type Kind
- type Number
- func (n *Number) AddFloat64(f float64)
- func (n *Number) AddFloat64Atomic(f float64)
- func (n *Number) AddInt64(i int64)
- func (n *Number) AddInt64Atomic(i int64)
- func (n *Number) AddNumber(kind Kind, nn Number)
- func (n *Number) AddNumberAtomic(kind Kind, nn Number)
- func (n *Number) AddRaw(kind Kind, r uint64)
- func (n *Number) AddRawAtomic(kind Kind, r uint64)
- func (n *Number) AsFloat64() float64
- func (n *Number) AsFloat64Atomic() float64
- func (n *Number) AsFloat64Ptr() *float64
- func (n *Number) AsInt64() int64
- func (n *Number) AsInt64Atomic() int64
- func (n *Number) AsInt64Ptr() *int64
- func (n *Number) AsInterface(kind Kind) interface{}
- func (n *Number) AsNumber() Number
- func (n *Number) AsNumberAtomic() Number
- func (n *Number) AsRaw() uint64
- func (n *Number) AsRawAtomic() uint64
- func (n *Number) AsRawPtr() *uint64
- func (n *Number) CoerceToFloat64(kind Kind) float64
- func (n *Number) CoerceToInt64(kind Kind) int64
- func (n *Number) CompareAndSwapFloat64(of, nf float64) bool
- func (n *Number) CompareAndSwapInt64(oi, ni int64) bool
- func (n *Number) CompareAndSwapNumber(on, nn Number) bool
- func (n *Number) CompareAndSwapRaw(or, nr uint64) bool
- func (n *Number) CompareFloat64(f float64) int
- func (n *Number) CompareInt64(i int64) int
- func (n *Number) CompareNumber(kind Kind, nn Number) int
- func (n *Number) CompareRaw(kind Kind, r uint64) int
- func (n *Number) Emit(kind Kind) string
- func (n *Number) IsNegative(kind Kind) bool
- func (n *Number) IsPositive(kind Kind) bool
- func (n *Number) IsZero(kind Kind) bool
- func (n *Number) SetFloat64(f float64)
- func (n *Number) SetFloat64Atomic(f float64)
- func (n *Number) SetInt64(i int64)
- func (n *Number) SetInt64Atomic(i int64)
- func (n *Number) SetNumber(nn Number)
- func (n *Number) SetNumberAtomic(nn Number)
- func (n *Number) SetRaw(r uint64)
- func (n *Number) SetRawAtomic(r uint64)
- func (n *Number) SwapFloat64(f float64) float64
- func (n *Number) SwapFloat64Atomic(f float64) float64
- func (n *Number) SwapInt64(i int64) int64
- func (n *Number) SwapInt64Atomic(i int64) int64
- func (n *Number) SwapNumber(nn Number) Number
- func (n *Number) SwapNumberAtomic(nn Number) Number
- func (n *Number) SwapRaw(r uint64) uint64
- func (n *Number) SwapRawAtomic(r uint64) uint64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Kind ¶
type Kind int8
Kind describes the data type of the Number.
type Number ¶
type Number uint64
Number represents either an integral or a floating point value. It needs to be accompanied with a source of Kind that describes the actual type of the value stored within Number.
func NewFloat64Number ¶
NewFloat64Number creates a floating point Number.
func NewInt64Number ¶
NewInt64Number creates an integral Number.
func NewNumberFromRaw ¶
NewNumberFromRaw creates a new Number from a raw value.
func NewNumberSignChange ¶
NewNumberSignChange returns a number with the same magnitude and the opposite sign. `kind` must describe the kind of number in `nn`.
func (*Number) AddFloat64 ¶
AddFloat64 assumes that the number contains a float64 and adds the passed float64 to it.
func (*Number) AddFloat64Atomic ¶
AddFloat64Atomic assumes that the number contains a float64 and adds the passed float64 to it atomically.
func (*Number) AddInt64 ¶
AddInt64 assumes that the number contains an int64 and adds the passed int64 to it.
func (*Number) AddInt64Atomic ¶
AddInt64Atomic assumes that the number contains an int64 and adds the passed int64 to it atomically.
func (*Number) AddNumber ¶
AddNumber assumes that this and the passed number are of the passed kind and adds the passed number to this number.
func (*Number) AddNumberAtomic ¶
AddNumberAtomic assumes that this and the passed number are of the passed kind and adds the passed number to this number atomically.
func (*Number) AddRaw ¶
AddRaw assumes that this number and the passed raw value are of the passed kind and adds the passed raw value to this number.
func (*Number) AddRawAtomic ¶
AddRawAtomic assumes that this number and the passed raw value are of the passed kind and adds the passed raw value to this number atomically.
func (*Number) AsFloat64 ¶
AsFloat64 assumes that the measurement value contains a float64 and returns it as such.
func (*Number) AsFloat64Atomic ¶
AsFloat64Atomic assumes that the measurement value contains a float64 and returns it as such atomically.
func (*Number) AsFloat64Ptr ¶
AsFloat64Ptr assumes that the number contains a float64 and returns a pointer to it.
func (*Number) AsInt64Atomic ¶
AsInt64Atomic assumes that the number contains an int64 and returns it as such atomically.
func (*Number) AsInt64Ptr ¶
AsInt64Ptr assumes that the number contains an int64 and returns a pointer to it.
func (*Number) AsInterface ¶
AsInterface returns the number as an interface{}, typically used for Kind-correct JSON conversion.
func (*Number) AsNumberAtomic ¶
AsNumberAtomic gets the Number atomically.
func (*Number) AsRaw ¶
AsRaw gets the uninterpreted raw value. Might be useful for some atomic operations.
func (*Number) AsRawAtomic ¶
AsRawAtomic gets the uninterpreted raw value atomically. Might be useful for some atomic operations.
func (*Number) AsRawPtr ¶
AsRawPtr gets the pointer to the raw, uninterpreted raw value. Might be useful for some atomic operations.
func (*Number) CoerceToFloat64 ¶
CoerceToFloat64 casts the number to float64. May result in data/precision loss.
func (*Number) CoerceToInt64 ¶
CoerceToInt64 casts the number to int64. May result in data/precision loss.
func (*Number) CompareAndSwapFloat64 ¶
CompareAndSwapFloat64 assumes that this number contains a float64 and does the atomic CAS operation on it.
func (*Number) CompareAndSwapInt64 ¶
CompareAndSwapInt64 assumes that this number contains an int64 and does the atomic CAS operation on it.
func (*Number) CompareAndSwapNumber ¶
CompareAndSwapNumber does the atomic CAS operation on this number. This number and passed old and new numbers should be of the same kind.
func (*Number) CompareAndSwapRaw ¶
CompareAndSwapRaw does the atomic CAS operation on this number. This number and passed old and new raw values should be of the same kind.
func (*Number) CompareFloat64 ¶
CompareFloat64 assumes that the Number contains a float64 and performs a comparison between the value and the other value. It returns the typical result of the compare function: -1 if the value is less than the other, 0 if both are equal, 1 if the value is greater than the other.
Do not compare NaN values.
func (*Number) CompareInt64 ¶
CompareInt64 assumes that the Number contains an int64 and performs a comparison between the value and the other value. It returns the typical result of the compare function: -1 if the value is less than the other, 0 if both are equal, 1 if the value is greater than the other.
func (*Number) CompareNumber ¶
CompareNumber compares two Numbers given their kind. Both numbers should have the same kind. This returns:
0 if the numbers are equal -1 if the subject `n` is less than the argument `nn` +1 if the subject `n` is greater than the argument `nn`
func (*Number) CompareRaw ¶
CompareRaw compares two numbers, where one is input as a raw uint64, interpreting both values as a `kind` of number.
func (*Number) Emit ¶
Emit returns a string representation of the raw value of the Number. A %d is used for integral values, %f for floating point values.
func (*Number) IsNegative ¶
IsNegative returns true if the actual value is less than zero.
func (*Number) IsPositive ¶
IsPositive returns true if the actual value is greater than zero.
func (*Number) SetFloat64 ¶
SetFloat64 assumes that the number contains a float64 and sets it to the passed value.
func (*Number) SetFloat64Atomic ¶
SetFloat64Atomic assumes that the number contains a float64 and sets it to the passed value atomically.
func (*Number) SetInt64 ¶
SetInt64 assumes that the number contains an int64 and sets it to the passed value.
func (*Number) SetInt64Atomic ¶
SetInt64Atomic assumes that the number contains an int64 and sets it to the passed value atomically.
func (*Number) SetNumber ¶
SetNumber sets the number to the passed number. Both should be of the same kind.
func (*Number) SetNumberAtomic ¶
SetNumberAtomic sets the number to the passed number atomically. Both should be of the same kind.
func (*Number) SetRaw ¶
SetRaw sets the number to the passed raw value. Both number and the raw number should represent the same kind.
func (*Number) SetRawAtomic ¶
SetRawAtomic sets the number to the passed raw value atomically. Both number and the raw number should represent the same kind.
func (*Number) SwapFloat64 ¶
SwapFloat64 assumes that the number contains an float64, sets it to the passed value and returns the old float64 value.
func (*Number) SwapFloat64Atomic ¶
SwapFloat64Atomic assumes that the number contains an float64, sets it to the passed value and returns the old float64 value atomically.
func (*Number) SwapInt64 ¶
SwapInt64 assumes that the number contains an int64, sets it to the passed value and returns the old int64 value.
func (*Number) SwapInt64Atomic ¶
SwapInt64Atomic assumes that the number contains an int64, sets it to the passed value and returns the old int64 value atomically.
func (*Number) SwapNumber ¶
SwapNumber sets the number to the passed number and returns the old number. Both this number and the passed number should be of the same kind.
func (*Number) SwapNumberAtomic ¶
SwapNumberAtomic sets the number to the passed number and returns the old number atomically. Both this number and the passed number should be of the same kind.
func (*Number) SwapRaw ¶
SwapRaw sets the number to the passed raw value and returns the old raw value. Both number and the raw number should represent the same kind.
func (*Number) SwapRawAtomic ¶
SwapRawAtomic sets the number to the passed raw value and returns the old raw value atomically. Both number and the raw number should represent the same kind.