Categorygithub.com/go-corelibs/maths
modulepackage
1.2.1
Repository: https://github.com/go-corelibs/maths.git
Documentation: pkg.go.dev

# README

godoc codecov Go Report Card

maths - mathematics and number-type utilities

maths is a package for general purpose mathematics and other number-type things.

Installation

> go get github.com/go-corelibs/maths@latest

Examples

Clamp, ToInt, IntegerLen

func main() {
    clamped := maths.Clamp(2.5, 0.0, 1.0)
    // clamped == float64(1.0)
    integer := maths.ToInt(10.0)
    // integer == int(10)
    count := maths.IntegerLen(1010)
    // count == 4
}

Go-CoreLibs

Go-CoreLibs is a repository of shared code between the Go-Curses and Go-Enjin projects.

License

Copyright 2023 The Go-CoreLibs Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use file except in compliance with the License.
You may obtain a copy of the license at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

# Functions

Atoi is a wrapper around strconv.Atoi with the given value converted to a string first using fmt.Sprintf with a "%v" replacement def is an optional default value if the strconv.Atoi call returns an error, only the first def value is ever used and if there are no def values provided, math.MaxInt is returned.
Ceil returns the value if it is less-than-or-equal-to the maximum and returns the maximum otherwise.
Clamp returns the value if it is greater-than-or-equal-to the minimum and less-than-or-equal-to the maximum arguments; if the value is less than the minimum, the minimum is returned; if the value is greater than the maximum, the maximum is returned.
DecimalLen returns the number of digits in the generic Decimal given.
Floor returns the value if it is greater-than-or-equal-to the minimum and returns the minimum otherwise.
IntegerLen returns the number of digits in the generic Integers given.
Round returns the value rounded to the nearest whole value.
RoundDown returns the value rounded down.
RoundUp returns the value rounded up.
ToFloat64 is a convenience wrapper around ToNumber with the primary difference that the "counld not convert and no default" case returns math.MaxFloat64 instead of zero.
ToInt is a convenience wrapper around ToNumber with the primary difference that the "counld not convert and no default" case returns math.MaxInt instead of zero.
ToInt64 is a convenience wrapper around ToNumber with the primary difference that the "counld not convert and no default" case returns math.MaxInt64 instead of zero.
ToNumber is a generic function for detecting the arbitrary value (v) type and converting the value (by recasting or by strconv parsing) to another Number type, using reflection to determine the correct means of conversion If the value given cannot be transformed into the requested Number type the "ok" return value will be false.
ToUint is a convenience wrapper around ToNumber with the primary difference that the "counld not convert and no default" case returns math.MaxUint instead of zero.
ToUint64 is a convenience wrapper around ToNumber with the primary difference that the "counld not convert and no default" case returns math.MaxUint64 instead of zero.

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author