dawson

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2018 License: MIT Imports: 4 Imported by: 6

README

dawson GoDoc GitHub version Go Report Card stable

package dawson is a package that provides utilities for testing involving floats.

Usage

To install: go get -u "gorgonia.org/dawson"

This package is fairly straightforwards. Import it in your _test.go files where you need to perform float comparisons.

Contributing

The best way to contribute is via Github issues. Open an issue on Github, and after a discussion feel free to send a pull request.

Trivia

This package is named after the awesome Bruce Dawson, who is most notable for his work on comparing floating points.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlikeC128

func AlikeC128(a, b complex128) bool

AlikeC128 checks that a and b are alike:

  • NaNs are considered to be equal
  • Both have the same sign bits for both the real and imaginary components

func AlikeF32

func AlikeF32(a, b float32) bool

AlikeF32 checks that a and b are alike:

  • NaNs are considered to be equal
  • Both have the same sign bits

func AlikeF64

func AlikeF64(a, b float64) bool

AlikeF64 checks that a and b are alike:

  • NaNs are considered to be equal
  • Both have the same sign bits

func AllClose

func AllClose(a, b interface{}, approxFn ...interface{}) bool

AllClose checks slices a and b are close together. An optional approximation function is accepted. If nothing is passed in, the CloseF64, CloseF32, CloseC128 functions will be used

This is not an exhasutive function. It only recognizes these types:

[]float64
[]float32
[]complex64
[]complex128

This function will panic if other types are passed in, or if a and b do not have matching types.

func CloseC128

func CloseC128(a, b complex128) bool

CloseC128 checks that a and b are within 1e-14 tolerance

func CloseEnoughF64

func CloseEnoughF64(a, b float64) bool

CloseEnoughF64 checks that a and b are within 1e-8 tolerance.

func CloseF32

func CloseF32(a, b float32) bool

CloseF32 checks that a and b are within 1e-5 tolerance. The tolerance number gotten from the cfloat standard. By contrast, Haskell's Linear package uses 1e-6 for floats

func CloseF64

func CloseF64(a, b float64) bool

CloseF64 checks that a and b are within 1e-14 tolerance.

func ToleranceC128

func ToleranceC128(a, b complex128, e float64) bool

ToleranceC128 is a test to see if two float64s, a and b are equal, within the specified tolerance e.

a: actual value
b: expected value
e: allowed errors (i.e. the values are within this range)

NOTE: e is a float64, which will be used in the individual comparison of both real and imaginary components

This function was adapted from the test files in the Go stdlib package math/cmplx, which has the Go licence.

func ToleranceF32

func ToleranceF32(a, b, e float32) bool

TolereranceF32 is a test to see if two float64s, a and b are equal, within the specified tolerance e.

a: actual value
b: expected value
e: allowed errors (i.e. the values are within this range)

This function was adapted from the test files of the package github.com/chewxy/math32, which in turn was adapted from the test files of the Go stdlib package math, which has the Go licence.

func ToleranceF64

func ToleranceF64(a, b, e float64) bool

ToleranceF64 is a test to see if two float64s, a and b are equal, within the specified tolerance e.

a: actual value
b: expected value
e: allowed errors (i.e. the values are within this range)

This function was taken from tthe test files in the Go stdlib package math, which has the Go licence.

func VeryCloseC128

func VeryCloseC128(a, b complex128) bool

VeryCloseC128 checks that a and b are within 1e-16 tolerance

func VeryCloseF32

func VeryCloseF32(a, b float32) bool

VeryCloseF32 checks that a and b are within 1e-6 tolerance. This number was acquired from Haskell's linear package, as well as wikipedia

func VeryCloseF64

func VeryCloseF64(a, b float64) bool

VeryCloseF64 checks that a and b are within 4e-16 tolerance.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL