-
Notifications
You must be signed in to change notification settings - Fork 49
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
String conversion from decimal (#108) #122
Changes from 1 commit
bb5f382
fb12295
6866965
55f7ffc
5689315
3c7131f
5a106b0
b296df7
cb2c910
df6b926
bd117d9
048efc0
9a76ab7
42313ad
7e0467a
7f61ee9
1d8f726
f4e6c19
84510f7
6e4f914
e25ce45
8420f46
3fc5f08
d6f32f6
8c858a1
078a8e6
2413444
2e6c49f
765b02b
3430ee5
cbdcdcb
38d53f3
ca9a5ea
9518831
ad5ba70
301af32
b5a4906
fb7ceef
4ef03d7
5587dd6
7ff0d8f
5019647
2f0b0b7
dcd75fd
0472e9b
d55274d
82fd325
35d62f2
88226a1
5ff06b0
091c3f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import ( | |
"io" | ||
"math/big" | ||
"math/bits" | ||
"strings" | ||
) | ||
|
||
const ( | ||
|
@@ -565,7 +566,25 @@ func (dst *Int) Scan(src interface{}) error { | |
} | ||
switch src := src.(type) { | ||
case string: | ||
return dst.SetFromDecimal(src) | ||
splt := strings.SplitN(src, "e", 2) | ||
if len(splt) < 2 { | ||
return dst.SetFromDecimal(src) | ||
} | ||
err := dst.SetFromDecimal(splt[0]) | ||
if err != nil { | ||
return err | ||
} | ||
if splt[1] == "0" { | ||
return nil | ||
} | ||
exp := new(Int) | ||
err = exp.SetFromDecimal(splt[1]) | ||
if err != nil { | ||
return err | ||
} | ||
exp.Exp(NewInt(10), exp) | ||
dst.Mul(dst, exp) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For
For IMO, it would have been ok if the failure-mode had been:
But I think the possible failures are different .. (?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think you are right here, they will be different. i think the popular postgresql scanner will error anyways if the value is too large to be scanned in, so I think that it is fine to do the same. |
||
return nil | ||
case []byte: | ||
return dst.SetFromDecimal(string(src)) | ||
} | ||
|
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.
1e0
should be1
, not0
... ?Not sure what
0e0
is defined as, need to check that.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.
isn't that what this will return? assume
X = splt[0], Y = splt[1]
I think XeY woudl be
X * 10 ^ Y
so0e0
should be0 * 10^0 = 0
In the previous lines, i do
dst.SetFromDecimal(X)
then if
Y == 0
, then i should just return, sinceX*10^0=X
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.
My bad, yes you're right