mirror of
https://github.com/robertkrimen/otto
synced 2025-10-12 20:27:30 +08:00
parent
d1b4d8ef0e
commit
7597815bd0
2
value.go
2
value.go
|
@ -857,7 +857,7 @@ func (value Value) toReflectValue(kind reflect.Kind) (reflect.Value, error) {
|
|||
if 0 > tmp1 {
|
||||
tmp1 = -tmp1
|
||||
}
|
||||
if tmp1 < math.SmallestNonzeroFloat32 || tmp1 > math.MaxFloat32 {
|
||||
if tmp1 > 0 && (tmp1 < math.SmallestNonzeroFloat32 || tmp1 > math.MaxFloat32) {
|
||||
return reflect.Value{}, fmt.Errorf("RangeError: %f (%v) to float32", tmp, value)
|
||||
} else {
|
||||
return reflect.ValueOf(float32(tmp)), nil
|
||||
|
|
|
@ -3,6 +3,7 @@ package otto
|
|||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -279,3 +280,12 @@ func TestExport(t *testing.T) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
func Test_toReflectValue(t *testing.T) {
|
||||
tt(t, func() {
|
||||
value := toValue(0.0)
|
||||
tmp, err := value.toReflectValue(reflect.Float32)
|
||||
is(tmp.Float(), 0.0)
|
||||
is(err, nil)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user