$98 GRAYBYTE WORDPRESS FILE MANAGER $36

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/usr/lib/golang/src/math/big/

HOME
Current File : /usr/lib/golang/src/math/big//floatmarsh.go
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// This file implements encoding/decoding of Floats.

package big

import (
	"errors"
	"fmt"
	"internal/byteorder"
)

// Gob codec version. Permits backward-compatible changes to the encoding.
const floatGobVersion byte = 1

// GobEncode implements the [encoding/gob.GobEncoder] interface.
// The [Float] value and all its attributes (precision,
// rounding mode, accuracy) are marshaled.
func (x *Float) GobEncode() ([]byte, error) {
	if x == nil {
		return nil, nil
	}

	// determine max. space (bytes) required for encoding
	sz := 1 + 1 + 4 // version + mode|acc|form|neg (3+2+2+1bit) + prec
	n := 0          // number of mantissa words
	if x.form == finite {
		// add space for mantissa and exponent
		n = int((x.prec + (_W - 1)) / _W) // required mantissa length in words for given precision
		// actual mantissa slice could be shorter (trailing 0's) or longer (unused bits):
		// - if shorter, only encode the words present
		// - if longer, cut off unused words when encoding in bytes
		//   (in practice, this should never happen since rounding
		//   takes care of it, but be safe and do it always)
		if len(x.mant) < n {
			n = len(x.mant)
		}
		// len(x.mant) >= n
		sz += 4 + n*_S // exp + mant
	}
	buf := make([]byte, sz)

	buf[0] = floatGobVersion
	b := byte(x.mode&7)<<5 | byte((x.acc+1)&3)<<3 | byte(x.form&3)<<1
	if x.neg {
		b |= 1
	}
	buf[1] = b
	byteorder.BEPutUint32(buf[2:], x.prec)

	if x.form == finite {
		byteorder.BEPutUint32(buf[6:], uint32(x.exp))
		x.mant[len(x.mant)-n:].bytes(buf[10:]) // cut off unused trailing words
	}

	return buf, nil
}

// GobDecode implements the [encoding/gob.GobDecoder] interface.
// The result is rounded per the precision and rounding mode of
// z unless z's precision is 0, in which case z is set exactly
// to the decoded value.
func (z *Float) GobDecode(buf []byte) error {
	if len(buf) == 0 {
		// Other side sent a nil or default value.
		*z = Float{}
		return nil
	}
	if len(buf) < 6 {
		return errors.New("Float.GobDecode: buffer too small")
	}

	if buf[0] != floatGobVersion {
		return fmt.Errorf("Float.GobDecode: encoding version %d not supported", buf[0])
	}

	oldPrec := z.prec
	oldMode := z.mode

	b := buf[1]
	z.mode = RoundingMode((b >> 5) & 7)
	z.acc = Accuracy((b>>3)&3) - 1
	z.form = form((b >> 1) & 3)
	z.neg = b&1 != 0
	z.prec = byteorder.BEUint32(buf[2:])

	if z.form == finite {
		if len(buf) < 10 {
			return errors.New("Float.GobDecode: buffer too small for finite form float")
		}
		z.exp = int32(byteorder.BEUint32(buf[6:]))
		z.mant = z.mant.setBytes(buf[10:])
	}

	if oldPrec != 0 {
		z.mode = oldMode
		z.SetPrec(uint(oldPrec))
	}

	if msg := z.validate0(); msg != "" {
		return errors.New("Float.GobDecode: " + msg)
	}

	return nil
}

// AppendText implements the [encoding.TextAppender] interface.
// Only the [Float] value is marshaled (in full precision), other
// attributes such as precision or accuracy are ignored.
func (x *Float) AppendText(b []byte) ([]byte, error) {
	if x == nil {
		return append(b, "<nil>"...), nil
	}
	return x.Append(b, 'g', -1), nil
}

// MarshalText implements the [encoding.TextMarshaler] interface.
// Only the [Float] value is marshaled (in full precision), other
// attributes such as precision or accuracy are ignored.
func (x *Float) MarshalText() (text []byte, err error) {
	return x.AppendText(nil)
}

// UnmarshalText implements the [encoding.TextUnmarshaler] interface.
// The result is rounded per the precision and rounding mode of z.
// If z's precision is 0, it is changed to 64 before rounding takes
// effect.
func (z *Float) UnmarshalText(text []byte) error {
	// TODO(gri): get rid of the []byte/string conversion
	_, _, err := z.Parse(string(text), 0)
	if err != nil {
		err = fmt.Errorf("math/big: cannot unmarshal %q into a *big.Float (%v)", text, err)
	}
	return err
}

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
16 Dec 2025 9.30 PM
root / root
0755
internal
--
16 Dec 2025 9.30 PM
root / root
0755
accuracy_string.go
0.632 KB
4 Dec 2025 6.06 PM
root / root
0644
arith.go
8.604 KB
4 Dec 2025 6.06 PM
root / root
0644
arith_386.s
4.864 KB
4 Dec 2025 6.06 PM
root / root
0644
arith_amd64.go
0.267 KB
4 Dec 2025 6.06 PM
root / root
0644
arith_amd64.s
8.676 KB
4 Dec 2025 6.06 PM
root / root
0644
arith_arm.s
6.373 KB
4 Dec 2025 6.06 PM
root / root
0644
arith_arm64.s
6.475 KB
4 Dec 2025 6.06 PM
root / root
0644
arith_decl.go
2.457 KB
4 Dec 2025 6.06 PM
root / root
0644
arith_decl_pure.go
0.638 KB
4 Dec 2025 6.06 PM
root / root
0644
arith_loong64.s
9.312 KB
4 Dec 2025 6.06 PM
root / root
0644
arith_mips64x.s
9.205 KB
4 Dec 2025 6.06 PM
root / root
0644
arith_mipsx.s
9.039 KB
4 Dec 2025 6.06 PM
root / root
0644
arith_ppc64x.s
6.672 KB
4 Dec 2025 6.06 PM
root / root
0644
arith_riscv64.s
9.027 KB
4 Dec 2025 6.06 PM
root / root
0644
arith_s390x.s
7.847 KB
4 Dec 2025 6.06 PM
root / root
0644
arith_wasm.s
0.507 KB
4 Dec 2025 6.06 PM
root / root
0644
arithvec_s390x.go
0.325 KB
4 Dec 2025 6.06 PM
root / root
0644
arithvec_s390x.s
8.676 KB
4 Dec 2025 6.06 PM
root / root
0644
calibrate.md
10.205 KB
4 Dec 2025 6.06 PM
root / root
0644
calibrate_graph.go
9.278 KB
4 Dec 2025 6.06 PM
root / root
0644
decimal.go
6.635 KB
4 Dec 2025 6.06 PM
root / root
0644
doc.go
3.804 KB
4 Dec 2025 6.06 PM
root / root
0644
float.go
44.528 KB
4 Dec 2025 6.06 PM
root / root
0644
floatconv.go
8.349 KB
4 Dec 2025 6.06 PM
root / root
0644
floatmarsh.go
3.882 KB
4 Dec 2025 6.06 PM
root / root
0644
ftoa.go
13.496 KB
4 Dec 2025 6.06 PM
root / root
0644
int.go
33.54 KB
4 Dec 2025 6.06 PM
root / root
0644
intconv.go
6.695 KB
4 Dec 2025 6.06 PM
root / root
0644
intmarsh.go
2.29 KB
4 Dec 2025 6.06 PM
root / root
0644
nat.go
24.725 KB
4 Dec 2025 6.06 PM
root / root
0644
natconv.go
15.596 KB
4 Dec 2025 6.06 PM
root / root
0644
natdiv.go
34.313 KB
4 Dec 2025 6.06 PM
root / root
0644
natmul.go
8.409 KB
4 Dec 2025 6.06 PM
root / root
0644
prime.go
10.536 KB
4 Dec 2025 6.06 PM
root / root
0644
rat.go
13.946 KB
4 Dec 2025 6.06 PM
root / root
0644
ratconv.go
12.634 KB
4 Dec 2025 6.06 PM
root / root
0644
ratmarsh.go
2.371 KB
4 Dec 2025 6.06 PM
root / root
0644
roundingmode_string.go
0.8 KB
4 Dec 2025 6.06 PM
root / root
0644
sqrt.go
2.793 KB
4 Dec 2025 6.06 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF