Skip to content

Commit

Permalink
valueBigInt ToFloat throw TypeError
Browse files Browse the repository at this point in the history
  • Loading branch information
shiroyk committed Aug 22, 2024
1 parent 5d79cc7 commit e9606b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions builtin_bigint.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (
type valueBigInt big.Int

func (v *valueBigInt) ToInteger() int64 {
panic(typeError("Cannot convert a BigInt value to a number"))
v.ToNumber()
return 0
}

func (v *valueBigInt) toString() String {
Expand All @@ -35,8 +36,8 @@ func (v *valueBigInt) String() string {
}

func (v *valueBigInt) ToFloat() float64 {
f, _ := new(big.Float).SetInt((*big.Int)(v)).Float64()
return f
v.ToNumber()
return 0
}

func (v *valueBigInt) ToNumber() Value {
Expand Down
3 changes: 3 additions & 0 deletions vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4441,6 +4441,9 @@ func cmp(px, py Value) Value {
}
}

px = toNumeric(px)
py = toNumeric(py)

switch nx := px.(type) {
case valueInt:
switch ny := py.(type) {
Expand Down

0 comments on commit e9606b3

Please sign in to comment.