Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The panic caused by NewFromFloat function makes trouble #306

Open
wxdyhj opened this issue Dec 17, 2022 · 0 comments
Open

The panic caused by NewFromFloat function makes trouble #306

wxdyhj opened this issue Dec 17, 2022 · 0 comments

Comments

@wxdyhj
Copy link

wxdyhj commented Dec 17, 2022

func NewFromFloat(value float64) Decimal {
	if value == 0 {
		return New(0, 0)
	}
	return newFromFloat(value, math.Float64bits(value), &float64info)
}


func newFromFloat(val float64, bits uint64, flt *floatInfo) Decimal {
	if math.IsNaN(val) || math.IsInf(val, 0) {
		panic(fmt.Sprintf("Cannot create a Decimal from %v", val))
	}
	// ...
}

the panic caused by newFromFloat function makes trouble.
How about returning error instead of panic, likes NewFromString function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant