mathx

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2024 License: MIT Imports: 9 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.

Float80 type from https://github.com/mewspring/mewmew-l modified a bit to read bytes instead of hex string

Was previously under unlicense/public domain but is under MIT license for fq

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 constraints.Ordered](a, b, v T) T

func DigitsInBase

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

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

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 Float80

type Float80 struct {
	// contains filtered or unexported fields
}

Float80 represents an 80-bit IEEE 754 extended precision floating-point value, in x86 extended precision format.

References:

https://en.wikipedia.org/wiki/Extended_precision#x86_extended_precision_format

func NewFloat80FromBits

func NewFloat80FromBits(se uint16, m uint64) Float80

NewFloat80FromBits returns a new 80-bit floating-point value based on the sign, exponent and mantissa bits.

func NewFloat80FromBytes

func NewFloat80FromBytes(b []byte) Float80

NewFloat80FromBytes returns a new 80-bit floating-point value based on b,

func NewFloat80FromFloat64

func NewFloat80FromFloat64(x float64) Float80

NewFloat80FromFloat64 returns the nearest 80-bit floating-point value for x.

func (Float80) BigFloat

func (f Float80) BigFloat() *big.Float

BigFloat returns the *big.Float representation of f.

func (Float80) Bits

func (f Float80) Bits() (se uint16, m uint64)

Bits returns the IEEE 754 binary representation of f, with the sign and exponent in se and the mantissa in m.

func (Float80) Bytes

func (f Float80) Bytes() []byte

Bytes returns the x86 extended precision binary representation of f as a byte slice.

func (Float80) Float64

func (f Float80) Float64() float64

Float64 returns the float64 representation of f.

func (Float80) String

func (f Float80) String() string

String returns the IEEE 754 binary representation of f as a string, containing 10 bytes in hexadecimal format.

Jump to

Keyboard shortcuts

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