Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitprincess committed Sep 21, 2022
1 parent e79cf97 commit 14c467c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
10 changes: 8 additions & 2 deletions encode.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package snum

import "math/big"

//------------------------------------------------------------------------------------------//
// binary - sorted

Expand All @@ -18,7 +20,10 @@ func (t *Encoder) Encode() (ret []byte, err error) {
var lenDecimal int
var isMinus bool
{
raw, lenDecimal, isMinus = t.Snum.GetRaw()
var bigRaw *big.Int
bigRaw, lenDecimal, isMinus = t.Snum.GetRaw()
raw = bigRaw.String()

// s_num 이 0일 경우 후처리
if raw == "0" {
lenDecimal = DEF_headerLenDecimal
Expand Down Expand Up @@ -108,7 +113,8 @@ func (t *Encoder) Decode(_num []byte) (err error) {

// snum 세팅 ( T_Snum 사용 )
{
t.Snum.SetRaw(s_raw, n_len__decimal, is_minus)
big, _ := big.NewInt(0).SetString(s_raw, 10)
t.Snum.SetRaw(big, n_len__decimal, is_minus)
}
return nil
}
Expand Down
24 changes: 11 additions & 13 deletions get_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"math"
"math/big"
"strconv"

"github.com/ericlagergren/decimal"
)
Expand All @@ -28,11 +27,11 @@ func (t *Snum) GetUint64() (u8 uint64, err error) {
return u8, nil
}

func (t *Snum) SetUint64(_u8 uint64) (err error) {
func (t *Snum) SetUint64(u8 uint64) (err error) {
if t.decimal == nil {
t.Init(0, 0)
}
t.decimal.SetUint64(_u8)
t.decimal.SetUint64(u8)

return nil
}
Expand Down Expand Up @@ -68,12 +67,12 @@ func (t *Snum) SetStr(_sn string) (err error) {
//----------------------------------------------------------------------------------------//
// raw

func (t *Snum) GetRaw() (sn string, lenDecimal int, isMinus bool) {
pu8, big := decimal.Raw(t.decimal.Reduce())
func (t *Snum) GetRaw() (big *big.Int, lenDecimal int, isMinus bool) {
pu8, pbig := decimal.Raw(t.decimal.Reduce())
if *pu8 < math.MaxUint64 { // under maxUint64
sn = strconv.FormatUint(*pu8, 10)
big = big.SetUint64(*pu8)
} else { // over maxUint64
sn = big.String()
big = pbig
}

// - 처리
Expand All @@ -82,19 +81,18 @@ func (t *Snum) GetRaw() (sn string, lenDecimal int, isMinus bool) {
}

lenDecimal = t.decimal.Scale()
return sn, lenDecimal, isMinus
return big, lenDecimal, isMinus
}

func (t *Snum) SetRaw(_sn string, _lenDecimal int, _isMinus bool) {
func (t *Snum) SetRaw(big *big.Int, lenDecimal int, isMinus bool) {
if t.decimal == nil {
t.Init(0, 0) // 임시
}
big := big.NewInt(0)
big.SetString(_sn, 10)
t.decimal.SetBigMantScale(big, _lenDecimal)

t.decimal.SetBigMantScale(big, lenDecimal)

// - 처리
if _isMinus == true {
if isMinus == true {
t.decimal.Neg(t.decimal)
}
}
Expand Down

0 comments on commit 14c467c

Please sign in to comment.