-
Notifications
You must be signed in to change notification settings - Fork 61
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
Error handling (panics, nan, inf) #4
Comments
I never felt good about the panics myself. They were in there primarily because I had not worked on incorporating
Yes. I've been working on this tonight and am planning on following the IEEE 754 |
BTW, math/big.Float doesn't support NaN. There is https://golang.org/pkg/math/big/#ErrNaN instead. Probably your library should use the same approach. |
Yeah. I'm curious how I'd handle cases like -Inf + -Inf where (to my I'd like to get away from NaN, though, since +/- Inf should be good enough
|
From https://golang.org/pkg/math/big/#Float.Add:
|
I wonder if it's worth adding traps to the Context so the user can decide There could be a flag (defaults to signaling?) that determines the behavior
|
I do not think I want to implement |
I think that a library like decimal should never panic. Generally inputs can come from users (e.g. from an HTML form) and it is much nicer to have an ability to handle errors without using recover or pre-validating decimals before each operation.
Have a look at
math/big.Accuracy
, I think it is better to use it instead ofbool
orerror
where it makes sense. E.g. https://golang.org/pkg/math/big/#Float.Uint64It might be good idea to introduce
+Inf
and-Inf
values for Decimal objects. This gives natural way to report errors for many operations, such as multiplying two large numbers, division by 0, parsing something like1e+908940390904920390109201902909201901
, etc.+/- Inf
big.Accuracy
The text was updated successfully, but these errors were encountered: