Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(498)

Delta Between Two Patch Sets: src/pkg/math/big/rat.go

Issue 6930059: code review 6930059: math/big: add Rat.{,Set}Float64 methods for IEEE 754 co... (Closed)
Left Patch Set: diff -r 3ef1c4fabb5f https://code.google.com/p/go/ Created 11 years, 2 months ago
Right Patch Set: diff -r 601795ce6319 https://code.google.com/p/go/ Created 11 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/pkg/math/big/rat_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2010 The Go Authors. All rights reserved. 1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // This file implements multi-precision rational numbers. 5 // This file implements multi-precision rational numbers.
6 6
7 package big 7 package big
8 8
9 import ( 9 import (
10 "encoding/binary" 10 "encoding/binary"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 158
159 f = math.Ldexp(float64(mantissa), exp-53) 159 f = math.Ldexp(float64(mantissa), exp-53)
160 if math.IsInf(f, 0) { 160 if math.IsInf(f, 0) {
161 exact = false 161 exact = false
162 } 162 }
163 return 163 return
164 } 164 }
165 165
166 // Float64 returns the nearest float64 value to z. 166 // Float64 returns the nearest float64 value to z.
167 // If z is exactly representable as a float64, Float64 returns exact=true. 167 // If z is exactly representable as a float64, Float64 returns exact=true.
168 // If z is negative, so too is f, even if f==0.
168 func (z *Rat) Float64() (f float64, exact bool) { 169 func (z *Rat) Float64() (f float64, exact bool) {
169 b := z.b.abs 170 b := z.b.abs
170 if len(b) == 0 { 171 if len(b) == 0 {
171 b = b.set(natOne) // materialize denominator 172 b = b.set(natOne) // materialize denominator
172 } 173 }
173 f, exact = quotToFloat(z.a.abs, b) 174 f, exact = quotToFloat(z.a.abs, b)
174 if z.a.neg { 175 if z.a.neg {
175 f = -f 176 f = -f
176 } 177 }
177 return 178 return
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 if b>>1 != ratGobVersion { 572 if b>>1 != ratGobVersion {
572 return errors.New(fmt.Sprintf("Rat.GobDecode: encoding version % d not supported", b>>1)) 573 return errors.New(fmt.Sprintf("Rat.GobDecode: encoding version % d not supported", b>>1))
573 } 574 }
574 const j = 1 + 4 575 const j = 1 + 4
575 i := j + binary.BigEndian.Uint32(buf[j-4:j]) 576 i := j + binary.BigEndian.Uint32(buf[j-4:j])
576 z.a.neg = b&1 != 0 577 z.a.neg = b&1 != 0
577 z.a.abs = z.a.abs.setBytes(buf[j:i]) 578 z.a.abs = z.a.abs.setBytes(buf[j:i])
578 z.b.abs = z.b.abs.setBytes(buf[i:]) 579 z.b.abs = z.b.abs.setBytes(buf[i:])
579 return nil 580 return nil
580 } 581 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b