Documentation ¶
Overview ¶
Package cscalar provides a set of helper routines for dealing with complex128 values.
Index ¶
- func EqualWithinAbs(a, b complex128, tol float64) bool
- func EqualWithinAbsOrRel(a, b complex128, absTol, relTol float64) bool
- func EqualWithinRel(a, b complex128, tol float64) bool
- func ParseWithNA(s, missing string) (value complex128, weight float64, err error)
- func Round(x complex128, prec int) complex128
- func RoundEven(x complex128, prec int) complex128
- func Same(a, b complex128) bool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EqualWithinAbs ¶
func EqualWithinAbs(a, b complex128, tol float64) bool
EqualWithinAbs returns true when a and b have an absolute difference not greater than tol.
func EqualWithinAbsOrRel ¶
func EqualWithinAbsOrRel(a, b complex128, absTol, relTol float64) bool
EqualWithinAbsOrRel returns true when a and b are equal to within the absolute or relative tolerances. See EqualWithinAbs and EqualWithinRel for details.
func EqualWithinRel ¶
func EqualWithinRel(a, b complex128, tol float64) bool
EqualWithinRel returns true when the difference between a and b is not greater than tol times the greater absolute value of a and b,
abs(a-b) <= tol * max(abs(a), abs(b)).
func ParseWithNA ¶
func ParseWithNA(s, missing string) (value complex128, weight float64, err error)
ParseWithNA converts the string s to a complex128 in value. If s equals missing, weight is returned as 0, otherwise 1.
Example ¶
package main import ( "bufio" "fmt" "log" "strings" "gonum.org/v1/gonum/cmplxs" "gonum.org/v1/gonum/cmplxs/cscalar" "gonum.org/v1/gonum/floats" ) func main() { // Calculate the mean of a list of numbers // ignoring missing values. const data = `6+2i missing 4-4i ` var ( vals []complex128 weights []float64 ) sc := bufio.NewScanner(strings.NewReader(data)) for sc.Scan() { v, w, err := cscalar.ParseWithNA(sc.Text(), "missing") if err != nil { log.Fatal(err) } vals = append(vals, v) weights = append(weights, w) } err := sc.Err() if err != nil { log.Fatal(err) } fmt.Println(cmplxs.Sum(vals) / complex(floats.Sum(weights), 0)) }
Output: (5-1i)
func Round ¶
func Round(x complex128, prec int) complex128
Round returns the half away from zero rounded value of x with prec precision.
Special cases are:
Round(±0) = +0 Round(±Inf) = ±Inf Round(NaN) = NaN
func RoundEven ¶
func RoundEven(x complex128, prec int) complex128
RoundEven returns the half even rounded value of x with prec precision.
Special cases are:
RoundEven(±0) = +0 RoundEven(±Inf) = ±Inf RoundEven(NaN) = NaN
func Same ¶
func Same(a, b complex128) bool
Same returns true when the inputs have the same value, allowing NaN equality.
Types ¶
This section is empty.