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

    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.

      const (
      	// Int64Kind means that the Number stores int64.
      	Int64Kind Kind = iota
      	// Float64Kind means that the Number stores float64.
      	Float64Kind
      )

      func (Kind) Maximum

      func (k Kind) Maximum() Number

        Maximum returns the maximum representable value for a given Kind

        func (Kind) Minimum

        func (k Kind) Minimum() Number

          Minimum returns the minimum representable value for a given Kind

          func (Kind) String

          func (i Kind) String() string

          func (Kind) Zero

          func (k Kind) Zero() Number

            Zero returns a zero value for a given Kind

            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

              func NewFloat64Number(f float64) Number

                NewFloat64Number creates a floating point Number.

                func NewInt64Number

                func NewInt64Number(i int64) Number

                  NewInt64Number creates an integral Number.

                  func NewNumberFromRaw

                  func NewNumberFromRaw(r uint64) Number

                    NewNumberFromRaw creates a new Number from a raw value.

                    func NewNumberSignChange

                    func NewNumberSignChange(kind Kind, nn Number) Number

                      NewNumberSignChange returns a number with the same magnitude and the opposite sign. `kind` must describe the kind of number in `nn`.

                      func (*Number) AddFloat64

                      func (n *Number) AddFloat64(f float64)

                        AddFloat64 assumes that the number contains a float64 and adds the passed float64 to it.

                        func (*Number) AddFloat64Atomic

                        func (n *Number) AddFloat64Atomic(f float64)

                          AddFloat64Atomic assumes that the number contains a float64 and adds the passed float64 to it atomically.

                          func (*Number) AddInt64

                          func (n *Number) AddInt64(i int64)

                            AddInt64 assumes that the number contains an int64 and adds the passed int64 to it.

                            func (*Number) AddInt64Atomic

                            func (n *Number) AddInt64Atomic(i int64)

                              AddInt64Atomic assumes that the number contains an int64 and adds the passed int64 to it atomically.

                              func (*Number) AddNumber

                              func (n *Number) AddNumber(kind Kind, nn Number)

                                AddNumber assumes that this and the passed number are of the passed kind and adds the passed number to this number.

                                func (*Number) AddNumberAtomic

                                func (n *Number) AddNumberAtomic(kind Kind, nn Number)

                                  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

                                  func (n *Number) AddRaw(kind Kind, r uint64)

                                    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

                                    func (n *Number) AddRawAtomic(kind Kind, r uint64)

                                      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

                                      func (n *Number) AsFloat64() float64

                                        AsFloat64 assumes that the measurement value contains a float64 and returns it as such.

                                        func (*Number) AsFloat64Atomic

                                        func (n *Number) AsFloat64Atomic() float64

                                          AsFloat64Atomic assumes that the measurement value contains a float64 and returns it as such atomically.

                                          func (*Number) AsFloat64Ptr

                                          func (n *Number) AsFloat64Ptr() *float64

                                            AsFloat64Ptr assumes that the number contains a float64 and returns a pointer to it.

                                            func (*Number) AsInt64

                                            func (n *Number) AsInt64() int64

                                              AsInt64 assumes that the value contains an int64 and returns it as such.

                                              func (*Number) AsInt64Atomic

                                              func (n *Number) AsInt64Atomic() int64

                                                AsInt64Atomic assumes that the number contains an int64 and returns it as such atomically.

                                                func (*Number) AsInt64Ptr

                                                func (n *Number) AsInt64Ptr() *int64

                                                  AsInt64Ptr assumes that the number contains an int64 and returns a pointer to it.

                                                  func (*Number) AsInterface

                                                  func (n *Number) AsInterface(kind Kind) interface{}

                                                    AsInterface returns the number as an interface{}, typically used for Kind-correct JSON conversion.

                                                    func (*Number) AsNumber

                                                    func (n *Number) AsNumber() Number

                                                      AsNumber gets the Number.

                                                      func (*Number) AsNumberAtomic

                                                      func (n *Number) AsNumberAtomic() Number

                                                        AsNumberAtomic gets the Number atomically.

                                                        func (*Number) AsRaw

                                                        func (n *Number) AsRaw() uint64

                                                          AsRaw gets the uninterpreted raw value. Might be useful for some atomic operations.

                                                          func (*Number) AsRawAtomic

                                                          func (n *Number) AsRawAtomic() uint64

                                                            AsRawAtomic gets the uninterpreted raw value atomically. Might be useful for some atomic operations.

                                                            func (*Number) AsRawPtr

                                                            func (n *Number) AsRawPtr() *uint64

                                                              AsRawPtr gets the pointer to the raw, uninterpreted raw value. Might be useful for some atomic operations.

                                                              func (*Number) CoerceToFloat64

                                                              func (n *Number) CoerceToFloat64(kind Kind) float64

                                                                CoerceToFloat64 casts the number to float64. May result in data/precision loss.

                                                                func (*Number) CoerceToInt64

                                                                func (n *Number) CoerceToInt64(kind Kind) int64

                                                                  CoerceToInt64 casts the number to int64. May result in data/precision loss.

                                                                  func (*Number) CompareAndSwapFloat64

                                                                  func (n *Number) CompareAndSwapFloat64(of, nf float64) bool

                                                                    CompareAndSwapFloat64 assumes that this number contains a float64 and does the atomic CAS operation on it.

                                                                    func (*Number) CompareAndSwapInt64

                                                                    func (n *Number) CompareAndSwapInt64(oi, ni int64) bool

                                                                      CompareAndSwapInt64 assumes that this number contains an int64 and does the atomic CAS operation on it.

                                                                      func (*Number) CompareAndSwapNumber

                                                                      func (n *Number) CompareAndSwapNumber(on, nn Number) bool

                                                                        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

                                                                        func (n *Number) CompareAndSwapRaw(or, nr uint64) bool

                                                                          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

                                                                          func (n *Number) CompareFloat64(f float64) int

                                                                            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

                                                                            func (n *Number) CompareInt64(i int64) int

                                                                              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

                                                                              func (n *Number) CompareNumber(kind Kind, nn Number) int

                                                                                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

                                                                                func (n *Number) CompareRaw(kind Kind, r uint64) int

                                                                                  CompareRaw compares two numbers, where one is input as a raw uint64, interpreting both values as a `kind` of number.

                                                                                  func (*Number) Emit

                                                                                  func (n *Number) Emit(kind Kind) string

                                                                                    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

                                                                                    func (n *Number) IsNegative(kind Kind) bool

                                                                                      IsNegative returns true if the actual value is less than zero.

                                                                                      func (*Number) IsPositive

                                                                                      func (n *Number) IsPositive(kind Kind) bool

                                                                                        IsPositive returns true if the actual value is greater than zero.

                                                                                        func (*Number) IsZero

                                                                                        func (n *Number) IsZero(kind Kind) bool

                                                                                          IsZero returns true if the actual value is equal to zero.

                                                                                          func (*Number) SetFloat64

                                                                                          func (n *Number) SetFloat64(f float64)

                                                                                            SetFloat64 assumes that the number contains a float64 and sets it to the passed value.

                                                                                            func (*Number) SetFloat64Atomic

                                                                                            func (n *Number) SetFloat64Atomic(f float64)

                                                                                              SetFloat64Atomic assumes that the number contains a float64 and sets it to the passed value atomically.

                                                                                              func (*Number) SetInt64

                                                                                              func (n *Number) SetInt64(i int64)

                                                                                                SetInt64 assumes that the number contains an int64 and sets it to the passed value.

                                                                                                func (*Number) SetInt64Atomic

                                                                                                func (n *Number) SetInt64Atomic(i int64)

                                                                                                  SetInt64Atomic assumes that the number contains an int64 and sets it to the passed value atomically.

                                                                                                  func (*Number) SetNumber

                                                                                                  func (n *Number) SetNumber(nn Number)

                                                                                                    SetNumber sets the number to the passed number. Both should be of the same kind.

                                                                                                    func (*Number) SetNumberAtomic

                                                                                                    func (n *Number) SetNumberAtomic(nn Number)

                                                                                                      SetNumberAtomic sets the number to the passed number atomically. Both should be of the same kind.

                                                                                                      func (*Number) SetRaw

                                                                                                      func (n *Number) SetRaw(r uint64)

                                                                                                        SetRaw sets the number to the passed raw value. Both number and the raw number should represent the same kind.

                                                                                                        func (*Number) SetRawAtomic

                                                                                                        func (n *Number) SetRawAtomic(r uint64)

                                                                                                          SetRawAtomic sets the number to the passed raw value atomically. Both number and the raw number should represent the same kind.

                                                                                                          func (*Number) SwapFloat64

                                                                                                          func (n *Number) SwapFloat64(f float64) float64

                                                                                                            SwapFloat64 assumes that the number contains an float64, sets it to the passed value and returns the old float64 value.

                                                                                                            func (*Number) SwapFloat64Atomic

                                                                                                            func (n *Number) SwapFloat64Atomic(f float64) float64

                                                                                                              SwapFloat64Atomic assumes that the number contains an float64, sets it to the passed value and returns the old float64 value atomically.

                                                                                                              func (*Number) SwapInt64

                                                                                                              func (n *Number) SwapInt64(i int64) int64

                                                                                                                SwapInt64 assumes that the number contains an int64, sets it to the passed value and returns the old int64 value.

                                                                                                                func (*Number) SwapInt64Atomic

                                                                                                                func (n *Number) SwapInt64Atomic(i int64) int64

                                                                                                                  SwapInt64Atomic assumes that the number contains an int64, sets it to the passed value and returns the old int64 value atomically.

                                                                                                                  func (*Number) SwapNumber

                                                                                                                  func (n *Number) SwapNumber(nn Number) Number

                                                                                                                    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

                                                                                                                    func (n *Number) SwapNumberAtomic(nn Number) Number

                                                                                                                      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

                                                                                                                      func (n *Number) SwapRaw(r uint64) uint64

                                                                                                                        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

                                                                                                                        func (n *Number) SwapRawAtomic(r uint64) uint64

                                                                                                                          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.