Skip to content

Commit

Permalink
feat: string to bigdecimal
Browse files Browse the repository at this point in the history
  • Loading branch information
r3v4s committed Mar 29, 2023
1 parent 8a5dc1e commit 7fdf79e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
14 changes: 0 additions & 14 deletions pkgs/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -2516,27 +2516,13 @@ func checkType(xt Type, dt Type, autoNative bool) {
"cannot use untyped rune as %s",
dt.Kind()))
}
case UintType, Uint64Type, Uint32Type, Uint16Type, Uint8Type:
switch dt.Kind() {
case BigintKind, IntKind, Int64Kind, Int32Kind, Int16Kind, Int8Kind,
UintKind, Uint64Kind, Uint32Kind, Uint16Kind, Uint8Kind:
return // ok
default:
println("DEBUG #1")
println("xt:", xt.String())
println("dt:", dt.String())
}
default:
if isUntyped(xt) {
panic("unexpected untyped type")
}
if xt.TypeID() == cdt.TypeID() {
return // ok
}

println("DEBUG #2")
println("xt:", xt.String())
println("dt:", dt.String())
}
case *PointerType:
if pt, ok := xt.(*PointerType); ok {
Expand Down
17 changes: 17 additions & 0 deletions pkgs/gnolang/values_conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,23 @@ GNO_CASE:
"cannot convert %s to %s",
tvk.String(), t.String()))
}
case PrimitiveType:
switch k {
case BigdecKind:
x := new(apd.Decimal)
x, _, err := x.SetString(tv.GetString())
if err != nil {
panic(err)
}

tv.V = BigdecValue{V: x}
tv.T = t
default:
panic(fmt.Sprintf(
"cannot convert %s to %s",
tvk.String(), t.String()))
}

default:
panic(fmt.Sprintf(
"cannot convert %s to %s",
Expand Down

0 comments on commit 7fdf79e

Please sign in to comment.