gonumgonum.org/v1/gonum/cmplxs/cscalar Index | Examples | Files

package cscalar

import "gonum.org/v1/gonum/cmplxs/cscalar"

Package cscalar provides a set of helper routines for dealing with complex128 values.




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.



package main

import (


func main() {
	// Calculate the mean of a list of numbers
	// ignoring missing values.
	const data = `6+2i

	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 {
		vals = append(vals, v)
		weights = append(weights, w)
	err := sc.Err()
	if err != nil {
	fmt.Println(cmplxs.Sum(vals) / complex(floats.Sum(weights), 0))




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.

Source Files

cscalar.go doc.go parse.go

v0.14.0 (latest)
Aug 19, 2023
6 packages
Last checked
6 days ago

Tools for package owners.