<commit_before>package consensus

import (
	"math/big"
)

// A Currency is a 128-bit signed integer. Currency operations are performed
// via math/big.
//
// The Currency object also keeps track of whether an overflow has occurred
// during arithmetic operations. Once the 'overflow' flag has been set to
// true, it can never be reset; a new Currency must be created. Callers can
// check for overflow using the Overflow method. This allows arithmetic
// operations to be chained together without needing to check an error value
// after each operation.
type Currency struct {
	b  [16]byte
	of bool // has an overflow ever occurred?
}

func NewCurrency(x uint64) *Currency {
	return BigToCurrency(new(big.Int).SetUint64(x))
}

func BigToCurrency(b *big.Int) *Currency {
	c := new(Currency)
	copy(c.b[:], b.Bytes())
	c.of = b.BitLen() > 128
	return c
}

func (c *Currency) SetBig(b *big.Int) *Currency {
	c.b = [16]byte{}
	copy(c.b[:], b.Bytes())
	c.of = c.of || b.BitLen() > 128 // preserve overflow flag
	return c
}

func (c *Currency) Big() *big.Int {
	return new(big.Int).SetBytes(c.b[:])
}

func (c *Currency) Add(y Currency) *Currency {
	return c.SetBig(new(big.Int).Add(c.Big(), y.Big()))
}

func (c *Currency) Sub(y Currency) *Currency {
	return c.SetBig(new(big.Int).Sub(c.Big(), y.Big()))
}

func (c *Currency) Mul(y Currency) *Currency {
	return c.SetBig(new(big.Int).Mul(c.Big(), y.Big()))
}

func (c *Currency) Div(y Currency) *Currency {
	return c.SetBig(new(big.Int).Div(c.Big(), y.Big()))
}

// Overflow returns whether an overflow has ever occurred while setting the
// value of c. The overflow is never cleared, even if the bits of c are reset.
func (c *Currency) Overflow() bool {
	return c.of
}

// MarshalSia implements the encoding.SiaMarshaler interface. The overflow
// flag is not included; an Currency will always be encoded as 16 bytes.
func (c Currency) MarshalSia() []byte {
	return c.b[:]
}
<commit_msg>add Sign and Cmp methods<commit_after>package consensus

import (
	"math/big"
)

// A Currency is a 128-bit signed integer. Currency operations are performed
// via math/big.
//
// The Currency object also keeps track of whether an overflow has occurred
// during arithmetic operations. Once the 'overflow' flag has been set to
// true, it can never be reset; a new Currency must be created. Callers can
// check for overflow using the Overflow method. This allows arithmetic
// operations to be chained together without needing to check an error value
// after each operation.
type Currency struct {
	b  [16]byte
	of bool // has an overflow ever occurred?
}

func NewCurrency(x uint64) *Currency {
	return BigToCurrency(new(big.Int).SetUint64(x))
}

func BigToCurrency(b *big.Int) *Currency {
	c := new(Currency)
	copy(c.b[:], b.Bytes())
	c.of = b.BitLen() > 128
	return c
}

func (c *Currency) SetBig(b *big.Int) *Currency {
	c.b = [16]byte{}
	copy(c.b[:], b.Bytes())
	c.of = c.of || b.BitLen() > 128 // preserve overflow flag
	return c
}

func (c *Currency) Big() *big.Int {
	return new(big.Int).SetBytes(c.b[:])
}

func (c *Currency) Add(y Currency) *Currency {
	return c.SetBig(new(big.Int).Add(c.Big(), y.Big()))
}

func (c *Currency) Sub(y Currency) *Currency {
	return c.SetBig(new(big.Int).Sub(c.Big(), y.Big()))
}

func (c *Currency) Mul(y Currency) *Currency {
	return c.SetBig(new(big.Int).Mul(c.Big(), y.Big()))
}

func (c *Currency) Div(y Currency) *Currency {
	return c.SetBig(new(big.Int).Div(c.Big(), y.Big()))
}

func (c *Currency) Sign() int {
	return c.Big().Sign()
}

func (c *Currency) Cmp(y Currency) int {
	return c.Big().Cmp(y.Big())
}

// Overflow returns whether an overflow has ever occurred while setting the
// value of c. The overflow is never cleared, even if the bits of c are reset.
func (c *Currency) Overflow() bool {
	return c.of
}

// MarshalSia implements the encoding.SiaMarshaler interface. The overflow
// flag is not included; an Currency will always be encoded as 16 bytes.
func (c Currency) MarshalSia() []byte {
	return c.b[:]
}

{'fraction_non_alphanumeric': 0.14296407185628743, 'fraction_numerical': 0.009481037924151697, 'mean_word_length': 3.8712029161603887, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6847871', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1399, 'n_words': 485}