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 as bit to read bytes instead of hex string
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org>
Index ¶
- Variables
- func BigIntSetBytesSigned(n *big.Int, buf []byte) *big.Int
- func Clamp[T constraints.Ordered](min, max, v T) T
- func DigitsInBase[T constraints.Integer](n T, basePrefix bool, base int) int
- func Max[T constraints.Ordered](v T, vs ...T) T
- func Min[T constraints.Ordered](v T, vs ...T) T
- func PadFormatBigInt(i *big.Int, base int, basePrefix bool, width int) string
- func PadFormatInt[T constraints.Signed](i T, base int, basePrefix bool, width int) string
- func PadFormatUint[T constraints.Unsigned](i T, base int, basePrefix bool, width int) string
- func TwosComplement(nBits int, n uint64) int64
- func ZigZag[U constraints.Unsigned, S constraints.Signed](n U) S
- type BitRange
- type Bits
- type Float16
- type Float80
Constants ¶
This section is empty.
Variables ¶
var BasePrefixMap = map[int]string{
2: "0b",
8: "0o",
16: "0x",
}
var BigIntOne = big.NewInt(1)
Functions ¶
func Clamp ¶
func Clamp[T constraints.Ordered](min, max, v T) T
func DigitsInBase ¶
func DigitsInBase[T constraints.Integer](n T, basePrefix bool, base int) int
func Max ¶
func Max[T constraints.Ordered](v T, vs ...T) T
func Min ¶
func Min[T constraints.Ordered](v T, vs ...T) T
func PadFormatBigInt ¶
func PadFormatInt ¶
func PadFormatUint ¶
func TwosComplement ¶
func ZigZag ¶
func ZigZag[U constraints.Unsigned, S constraints.Signed](n U) S
decode zigzag encoded integer https://developers.google.com/protocol-buffers/docs/encoding
Types ¶
type BitRange ¶
func (BitRange) StringByteBits ¶
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 ¶
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 ¶
Float16Inf returns positive infinity if sign >= 0, negative infinity if sign < 0.
func (Float16) Float32 ¶
Float32 returns the Float16 value expanded to a float32. Infinities and NaNs are expanded as such.
type Float80 ¶ added in v0.5.0
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 ¶ added in v0.5.0
NewFloat80FromBits returns a new 80-bit floating-point value based on the sign, exponent and mantissa bits.
func NewFloat80FromBytes ¶ added in v0.5.0
NewFloat80FromBytes returns a new 80-bit floating-point value based on b,
func NewFloat80FromFloat64 ¶ added in v0.5.0
NewFloat80FromFloat64 returns the nearest 80-bit floating-point value for x.
func (Float80) Bits ¶ added in v0.5.0
Bits returns the IEEE 754 binary representation of f, with the sign and exponent in se and the mantissa in m.
func (Float80) Bytes ¶ added in v0.5.0
Bytes returns the x86 extended precision binary representation of f as a byte slice.