math

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 License: MIT Imports: 4 Imported by: 0

README

Go Reference

Functional Math

It is doubtful that this package will be useful to many. It is mostly wrapping some of the functions from the standard library math and strconv packages to make them generic and take care of ugly casting for the caller (you can use int and not have to cast it to float64 and back). Below are the functions that are here. As I am pretty much just wrapping standard functions, I did not write any tests.

Get it

go get -u github.com/flowonyx/functional/math

Use it

import "github.com/flowonyx/functional/math"

Functions

  • Abs returns the absolute value of x.
  • RoundInt returns the nearest integer as an int, rounding half away from zero.
  • Round returns the nearest integer as the float type of x, rounding half away from zero.
  • RoundToEven returns the nearest integer as the float type of x, rounding ties to even.
  • RoundToEvenInt returns the nearest integer as an int, rounding ties to even.
  • Cbrt returns the cube root of x.
  • CopySign returns a value with the magnitude of x and the sign of y.
  • Dim returns the maximum of x-y or 0.
  • Pow returns x**y, the base-x exponential of y.
  • Pow10 returns 10**n, the base-10 exponential of n.
  • Remainder returns the IEEE 754 floating-point remainder of x/y.
  • Sqrt returns the square root of a number.
  • Max returns the maximum value of two numbers.
  • Min returns the minimum value of two numbers.
  • TryParseInt returns the Integer parsed from a string as an option.Option. If parsing fails, it returns None.

Documentation

Overview

Package math provides some generic mathematical functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[T constraints.Signed](x T) T

Abs returns the absolute value of x.

func Cbrt

func Cbrt[T numeric](x T) T

Cbrt returns the cube root of x.

func CopySign

func CopySign[T1, T2 constraints.Signed](x T1, y T2) T1

CopySign returns a value with the magnitude of x and the sign of y.

func Dim

func Dim[T numeric](x, y T) T

Dim returns the maximum of x-y or 0.

func Max

func Max[T constraints.Ordered](x, y T) T

Max returns the maximum value of x or y.

func Min

func Min[T constraints.Ordered](x, y T) T

Min returns the minimum value of x or y.

func Pow

func Pow[T numeric](x, y T) T

Pow returns x**y, the base-x exponential of y.

func Pow10

func Pow10[T constraints.Integer](x T) T

Pow10 returns 10**n, the base-10 exponential of n.

func Remainder

func Remainder[T numeric](x, y T) T

Remainder returns the IEEE 754 floating-point remainder of x/y.

func Round

func Round[T constraints.Float](x T) T

Round returns the nearest integer as the float type of x, rounding half away from zero.

func RoundInt

func RoundInt[T constraints.Float](x T) int

RoundInt returns the nearest integer as an int, rounding half away from zero.

func RoundToEven

func RoundToEven[T constraints.Float](x T) T

RoundToEven returns the nearest integer as the float type of x, rounding ties to even.

func RoundToEvenInt

func RoundToEvenInt[T constraints.Float](x T) int

RoundToEvenInt returns the nearest integer as an int, rounding ties to even.

func Sqrt

func Sqrt[T constraints.Integer](x T) T

Sqrt returns the square root of x.

func TryParseInt

func TryParseInt[T constraints.Integer](s string) option.Option[T]

TryParseInt returns the integer parsed from s as an Option. If parsing fails, it returns None.

Types

This section is empty.

Jump to

Keyboard shortcuts

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