$56 GRAYBYTE WORDPRESS FILE MANAGER $96

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//ratmarsh.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 Rats.

package big

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

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

// GobEncode implements the [encoding/gob.GobEncoder] interface.
func (x *Rat) GobEncode() ([]byte, error) {
	if x == nil {
		return nil, nil
	}
	buf := make([]byte, 1+4+(len(x.a.abs)+len(x.b.abs))*_S) // extra bytes for version and sign bit (1), and numerator length (4)
	i := x.b.abs.bytes(buf)
	j := x.a.abs.bytes(buf[:i])
	n := i - j
	if int(uint32(n)) != n {
		// this should never happen
		return nil, errors.New("Rat.GobEncode: numerator too large")
	}
	byteorder.BEPutUint32(buf[j-4:j], uint32(n))
	j -= 1 + 4
	b := ratGobVersion << 1 // make space for sign bit
	if x.a.neg {
		b |= 1
	}
	buf[j] = b
	return buf[j:], nil
}

// GobDecode implements the [encoding/gob.GobDecoder] interface.
func (z *Rat) GobDecode(buf []byte) error {
	if len(buf) == 0 {
		// Other side sent a nil or default value.
		*z = Rat{}
		return nil
	}
	if len(buf) < 5 {
		return errors.New("Rat.GobDecode: buffer too small")
	}
	b := buf[0]
	if b>>1 != ratGobVersion {
		return fmt.Errorf("Rat.GobDecode: encoding version %d not supported", b>>1)
	}
	const j = 1 + 4
	ln := byteorder.BEUint32(buf[j-4 : j])
	if uint64(ln) > math.MaxInt-j {
		return errors.New("Rat.GobDecode: invalid length")
	}
	i := j + int(ln)
	if len(buf) < i {
		return errors.New("Rat.GobDecode: buffer too small")
	}
	z.a.neg = b&1 != 0
	z.a.abs = z.a.abs.setBytes(buf[j:i])
	z.b.abs = z.b.abs.setBytes(buf[i:])
	return nil
}

// AppendText implements the [encoding.TextAppender] interface.
func (x *Rat) AppendText(b []byte) ([]byte, error) {
	if x.IsInt() {
		return x.a.AppendText(b)
	}
	return x.marshal(b), nil
}

// MarshalText implements the [encoding.TextMarshaler] interface.
func (x *Rat) MarshalText() (text []byte, err error) {
	return x.AppendText(nil)
}

// UnmarshalText implements the [encoding.TextUnmarshaler] interface.
func (z *Rat) UnmarshalText(text []byte) error {
	// TODO(gri): get rid of the []byte/string conversion
	if _, ok := z.SetString(string(text)); !ok {
		return fmt.Errorf("math/big: cannot unmarshal %q into a *big.Rat", text)
	}
	return nil
}

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