func (d Decimal128) IsNaN() bool {
	return d.h>>58&(1<<5-1) == 0x1F
}
IsNaN returns whether d is NaN.
package primitive
import (
	"encoding/json"
	"errors"
	"fmt"
	"math/big"
	"regexp"
	"strconv"
	"strings"
)
const (
	MaxDecimal128Exp = 6111
	MinDecimal128Exp = -6176
)
var (
	ErrParseNaN    = errors.New("cannot parse NaN as a *big.Int")
	ErrParseInf    = errors.New("cannot parse Infinity as a *big.Int")
	ErrParseNegInf = errors.New("cannot parse -Infinity as a *big.Int")
)
type Decimal128 struct {
	h, l uint64
}
func NewDecimal128(h, l uint64) Decimal128 {
	return Decimal128{h: h, l: l}
}
func (d Decimal128) GetBytes() (uint64, uint64) {
	return d.h, d.l
}
func (d Decimal128) String() string {
	var posSign int       
	var exp int           
	var high, low uint64  
	if d.h>>63&1 == 0 {
		posSign = 1
	}
	switch d.h >> 58 & (1<<5 - 1) {
	case 0x1F:
		return "NaN"
	case 0x1E:
		return "-Infinity"[posSign:]
	}
	low = d.l
	if d.h>>61&3 == 3 {
		exp = int(d.h >> 47 & (1<<14 - 1))
		high, low = 0, 0
	} else {
		exp = int(d.h >> 49 & (1<<14 - 1))
		high = d.h & (1<<49 - 1)
	}
	exp += MinDecimal128Exp
	if high == 0 && low == 0 && exp == 0 {
		return "-0"[posSign:]
	}
	var repr [48]byte  
	var last = len(repr)
	var i = len(repr)
	var dot = len(repr) + exp
	var rem uint32
Loop:
	for d9 := 0; d9 < 5; d9++ {
		high, low, rem = divmod(high, low, 1e9)
		for d1 := 0; d1 < 9; d1++ {
			if i < len(repr) && (dot == i || low == 0 && high == 0 && rem > 0 && rem < 10 && (dot < i-6 || exp > 0)) {
				exp += len(repr) - i
				i--
				repr[i] = '.'
				last = i - 1
				dot = len(repr)  
			}
			c := '0' + byte(rem%10)
			rem /= 10
			i--
			repr[i] = c
			if low == 0 && high == 0 && rem == 0 && i == len(repr)-1 && (dot < i-5 || exp > 0) {
				last = i
				break Loop
			}
			if c != '0' {
				last = i
			}
			if dot > i && low == 0 && high == 0 && rem == 0 {
				break Loop
			}
		}
	}
	repr[last-1] = '-'
	last--
	if exp > 0 {
		return string(repr[last+posSign:]) + "E+" + strconv.Itoa(exp)
	}
	if exp < 0 {
		return string(repr[last+posSign:]) + "E" + strconv.Itoa(exp)
	}
	return string(repr[last+posSign:])
}
func (d Decimal128) BigInt() (bi *big.Int, exp int, err error) {
	high, low := d.GetBytes()
	var posSign bool  
	posSign = high>>63&1 == 0
	switch high >> 58 & (1<<5 - 1) {
	case 0x1F:
		return nil, 0, ErrParseNaN
	case 0x1E:
		if posSign {
			return nil, 0, ErrParseInf
		}
		return nil, 0, ErrParseNegInf
	}
	if high>>61&3 == 3 {
		exp = int(high >> 47 & (1<<14 - 1))
		high, low = 0, 0
	} else {
		exp = int(high >> 49 & (1<<14 - 1))
		high = high & (1<<49 - 1)
	}
	exp += MinDecimal128Exp
	if high == 0 && low == 0 && exp == 0 {
		if posSign {
			return new(big.Int), 0, nil
		}
		return new(big.Int), 0, nil
	}
	bi = big.NewInt(0)
	const host32bit = ^uint(0)>>32 == 0
	if host32bit {
		bi.SetBits([]big.Word{big.Word(low), big.Word(low >> 32), big.Word(high), big.Word(high >> 32)})
	} else {
		bi.SetBits([]big.Word{big.Word(low), big.Word(high)})
	}
	if !posSign {
		return bi.Neg(bi), exp, nil
	}
	return
}