File tree Expand file tree Collapse file tree 2 files changed +17
-5
lines changed
Expand file tree Collapse file tree 2 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -514,11 +514,12 @@ func (x *Big) Float64() (f float64, ok bool) {
514514 case xc == 0 :
515515 ok = true
516516 case x .IsInt ():
517- if xc , ok = x .Uint64 (); ! ok {
518- v , _ := x .Int64 ()
519- xc = uint64 (v )
517+ if xc , ok := x .Int64 (); ok {
518+ f = float64 (xc )
519+ } else if xc , ok := x .Uint64 (); ok {
520+ f = float64 (xc )
520521 }
521- fallthrough
522+ ok = xc < maxMantissa || ( xc & ( xc - 1 )) == 0
522523 case x .exp == 0 :
523524 f = float64 (xc )
524525 ok = xc < maxMantissa || (xc & (xc - 1 )) == 0
Original file line number Diff line number Diff line change @@ -83,6 +83,17 @@ func TestIssue105(t *testing.T) {
8383 var b Big
8484 b .SetString ("6190.000000000000" )
8585 if _ , ok := b .Float64 (); ! ok {
86- t .Fatalf ("6190 should fit in a float just fine" )
86+ t .Fatal ("6190 should fit in a float just fine" )
87+ }
88+ }
89+
90+ func TestIssue114 (t * testing.T ) {
91+ val := New (- 1 , 0 )
92+ f , ok := val .Float64 ()
93+ if ! ok {
94+ t .Fatal ("expected true, got false" )
95+ }
96+ if f != - 1 {
97+ t .Fatalf ("expected -1, got %f" , f )
8798 }
8899}
You can’t perform that action at this time.
0 commit comments