mathex

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Copyright (C) 2014 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this 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.

Index

Constants

This section is empty.

Variables

View Source
var BasePrefixMap = map[int]string{
	2:  "0b",
	8:  "0o",
	16: "0x",
}
View Source
var BigIntOne = big.NewInt(1)

Functions

func BigIntSetBytesSigned

func BigIntSetBytesSigned(n *big.Int, buf []byte) *big.Int

func Clamp

func Clamp[T Number](min, max, v T) T

func DigitsInBase

func DigitsInBase[T constraints.Integer](n T, basePrefix bool, base int) int

func Max

func Max[T Number](v T, vs ...T) T

func Min

func Min[T Number](v T, vs ...T) T

func PadFormatBigInt

func PadFormatBigInt(i *big.Int, base int, basePrefix bool, width int) string

func PadFormatInt

func PadFormatInt[T constraints.Signed](i T, base int, basePrefix bool, width int) string

func PadFormatUint

func PadFormatUint[T constraints.Unsigned](i T, base int, basePrefix bool, width int) string

func TwosComplement

func TwosComplement(nBits int, n uint64) int64

func ZigZag

func ZigZag(n uint64) int64

decode zigzag encoded integer https://developers.google.com/protocol-buffers/docs/encoding

Types

type BitRange

type BitRange ranges.Range

func (BitRange) StringByteBits

func (r BitRange) StringByteBits(base int) string

type Bits

type Bits uint64

func (Bits) StringByteBits

func (b Bits) StringByteBits(base int) string

type Float16

type Float16 uint16

Float16 represents a 16-bit floating point number, containing a single sign bit, 5 exponent bits and 10 fractional bits. This corresponds to IEEE 754-2008 binary16 (or half precision float) type.

 MSB                                                                         LSB
╔════╦════╤════╤════╤════╤════╦════╤════╤════╤════╤════╤════╤════╤════╤════╤════╗
║Sign║ E₄ │ E₃ │ E₂ │ E₁ │ E₀ ║ F₉ │ F₈ │ F₇ │ F₆ │ F₅ │ F₄ │ F₃ │ F₂ │ F₁ │ F₀ ║
╚════╩════╧════╧════╧════╧════╩════╧════╧════╧════╧════╧════╧════╧════╧════╧════╝
Where E is the exponent bits and F is the fractional bits.

func NewFloat16

func NewFloat16(f32 float32) Float16

NewFloat16 returns a Float16 encoding of a 32-bit floating point number. Infinities and NaNs are encoded as such. Very large and very small numbers get rounded to infinity and zero respectively.

func NewFloat16Inf

func NewFloat16Inf(sign int) Float16

Float16Inf returns positive infinity if sign >= 0, negative infinity if sign < 0.

func NewFloat16NaN

func NewFloat16NaN() Float16

Float16NaN returns an “not-a-number” value.

func (Float16) Float32

func (f Float16) Float32() float32

Float32 returns the Float16 value expanded to a float32. Infinities and NaNs are expanded as such.

func (Float16) IsInf

func (f Float16) IsInf(sign int) bool

IsInf reports whether f is an infinity, according to sign. If sign > 0, IsInf reports whether f is positive infinity. If sign < 0, IsInf reports whether f is negative infinity. If sign == 0, IsInf reports whether f is either infinity.

func (Float16) IsNaN

func (f Float16) IsNaN() bool

IsNaN reports whether f is an “not-a-number” value.

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

Jump to

Keyboard shortcuts

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