-
Notifications
You must be signed in to change notification settings - Fork 646
decimal: add decomposer interface #141
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
Conversation
Please let me know what you think of this idea. See referenced issue. |
e0fa0ad
to
3d1147e
Compare
S string // String value. | ||
E bool // Expect an error. | ||
}{ | ||
{N: "Normal-1", S: "123.456"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these test cases include expected results which are then tested against the actual results with assert.Equal
? It would be good to have more test cases as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any uses of an "assert" package, but, I added more test cases, it already checks with Decimal.Cmp and I added a check to the original S. Because this is a round trip test, I'm checking the final decimal against the original parsed number.
// Compose sets the internal decimal value from parts. If the value cannot be | ||
// represented then an error should be returned. | ||
func (d *Decimal) Compose(form byte, negative bool, coefficient []byte, exponent int32) error { | ||
switch form { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These forms should constants rather than magic numbers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added consts above. The interface is designed to be a byte type to allow it to not rely on an external package for types.
case 0: | ||
// Set rest of finite form below. | ||
case 1: | ||
return fmt.Errorf("Infinite form not supported") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why even include these cases, or have the form argument at all, if they cannot be accepted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This interface is designed to convert between many different decimal packages. Some of these other packages handle NaN and and Infinite forms. This is to have explicit error messages for messaging.
e8157b0
to
a866c9d
Compare
I removed the use of testing.T.Run, which was introduced in Go1.7. CI passes now. |
Ping. |
a866c9d
to
140db38
Compare
Ping |
@njason Can we resume this conversation? This is in Go1.13 and crdb/apd and ericlagergren/decimal. |
@kardianos I see this has been added as an experimental interface to 1.13 which is in an unstable release state. Please circle back when this is in a stable release. |
1.13 has now been released. |
Can we remove the |
140db38
to
fe30a7b
Compare
fe30a7b
to
75bb2cb
Compare
The most recent build on TravisCI complained about Go1.2 being missing. Looking on https://golang.org/dl/ Go 1.2.2 is present, but Go1.2 is indeed gone. To test, I changed the travis ci file and it passed using Go1.2.2. |
Also, I removed the interface per your request. |
Hello everyone After this update i got error: I'm using: |
@5teven What is the postgresql driver version? Also, please open a new issue at golang.org/issue and @ me. |
After this update i got error: go 1.13.4 i think go mysql driver can't support decimalDecompose. please see:
2.go-sql-driver/mysql statement.go line 140, method ConvertValue:
`
line 1071 |
commit 75bb2cb has been reverted from master and will be worked on in another branch |
decimal: add decomposer interface
For golang/go#30870