summaryrefslogtreecommitdiff
path: root/src/math/big/float.go
Commit message (Collapse)AuthorAgeFilesLines
* all: gofmt main repoRuss Cox2022-04-111-4/+4
| | | | | | | | | | | | | | | [This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* all: remove trailing blank doc comment linesRuss Cox2022-04-011-3/+0
| | | | | | | | | | | | | | | | | | | | | | | | A future change to gofmt will rewrite // Doc comment. // func f() to // Doc comment. func f() Apply that change preemptively to all doc comments. For #51082. Change-Id: I4023e16cfb0729b64a8590f071cd92f17343081d Reviewed-on: https://go-review.googlesource.com/c/go/+/384259 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* math/big: clarified doc string for SetMantExpRobert Griesemer2021-08-221-1/+3
| | | | | | | | | | | Fixes #47879. Change-Id: I35efb5fc65c4f1eb1b45918f95bbe1ff4039950e Reviewed-on: https://go-review.googlesource.com/c/go/+/344249 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
* math/big: add a comment for SetMantExpsurechen2020-08-281-3/+4
| | | | | | | | Change-Id: I9ff5d1767cf70648c2251268e5e815944a7cb371 Reviewed-on: https://go-review.googlesource.com/c/go/+/233737 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
* math/big: document that Sqrt doesn't set AccuracyAlberto Donizetti2020-03-201-1/+3
| | | | | | | | | | | Document that the Float.Sqrt method does not set the receiver's Accuracy field. Updates #37915 Change-Id: Ief1dcac07eacc0ef02f86bfac9044501477bca1c Reviewed-on: https://go-review.googlesource.com/c/go/+/224497 Reviewed-by: Robert Griesemer <gri@golang.org>
* all: use "reports whether" consistently in the few places that didn'tBrad Fitzpatrick2018-11-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Go documentation style for boolean funcs is to say: // Foo reports whether ... func Foo() bool (rather than "returns true if") This CL also replaces 4 uses of "iff" with the same "reports whether" wording, which doesn't lose any meaning, and will prevent people from sending typo fixes when they don't realize it's "if and only if". In the past I think we've had the typo CLs updated to just say "reports whether". So do them all at once. (Inspired by the addition of another "returns true if" in CL 146938 in fd_plan9.go) Created with: $ perl -i -npe 's/returns true if/reports whether/' $(git grep -l "returns true iff" | grep -v vendor) $ perl -i -npe 's/returns true if/reports whether/' $(git grep -l "returns true if" | grep -v vendor) Change-Id: Ided502237f5ab0d25cb625dbab12529c361a8b9f Reviewed-on: https://go-review.googlesource.com/c/147037 Reviewed-by: Ian Lance Taylor <iant@golang.org>
* math/big: shallow copies of Int/Rat/Float are not supported (documentation)Robert Griesemer2018-10-291-1/+7
| | | | | | | | Fixes #28423. Change-Id: Ie57ade565d0407a4bffaa86fb4475ff083168e79 Reviewed-on: https://go-review.googlesource.com/c/145537 Reviewed-by: Ian Lance Taylor <iant@golang.org>
* all: fix a bunch of misspellingsIgor Zhilianin2018-10-061-1/+1
| | | | | | | | | | Change-Id: If2954bdfc551515403706b2cd0dde94e45936e08 GitHub-Last-Rev: d4cfc41a5504cf10befefdb881d4c45986a1d1f8 GitHub-Pull-Request: golang/go#28049 Reviewed-on: https://go-review.googlesource.com/c/140299 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* math/big: round x + (-x) to -0 for mode ToNegativeInfBrian Kessler2018-06-141-2/+6
| | | | | | | | | | | | | | | | | | | | | | Handling of sign bit as defined by IEEE 754-2008, section 6.3: When the sum of two operands with opposite signs (or the difference of two operands with like signs) is exactly zero, the sign of that sum (or difference) shall be +0 in all rounding-direction attributes except roundTowardNegative; under that attribute, the sign of an exact zero sum (or difference) shall be −0. However, x+x = x−(−x) retains the same sign as x even when x is zero. This change handles the special case of Add/Sub resulting in exactly zero when the rounding mode is ToNegativeInf setting the sign bit accordingly. Fixes #25798 Change-Id: I4d0715fa3c3e4a3d8a4d7861dc1d6423c8b1c68c Reviewed-on: https://go-review.googlesource.com/117495 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
* all: update comment URLs from HTTP to HTTPS, where possibleTim Cooper2018-06-011-1/+1
| | | | | | | | | | Each URL was manually verified to ensure it did not serve up incorrect content. Change-Id: I4dc846227af95a73ee9a3074d0c379ff0fa955df Reviewed-on: https://go-review.googlesource.com/115798 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
* math/big: recognize squaring for FloatsBrian Kessler2017-08-181-2/+5
| | | | | | | | | | | | | Updates #13745 Recognize z.Mul(x, x) as squaring for Floats and use the internal z.sqr(x) method for nat on the mantissa. Change-Id: I0f792157bad93a13cae1aecc4c10bd20c6397693 Reviewed-on: https://go-review.googlesource.com/56774 Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* math/big: avoid unneeded sticky bit calculationsBrian Kessler2017-08-111-2/+3
| | | | | | | | | | | | | | As noted in the TODO comment, the sticky bit is only used when the rounding bit is zero or the rounding mode is ToNearestEven. This change makes that check explicit and will eliminate half the sticky bit calculations on average when rounding mode is not ToNearestEven. Change-Id: Ia4709f08f46e682bf97dabe5eb2a10e8e3d7af43 Reviewed-on: https://go-review.googlesource.com/54111 Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
* math/big: fix Add, Sub when receiver aliases 2nd operandAlberto Donizetti2017-05-311-2/+11
| | | | | | | | | | Fixes #20490 Change-Id: I9cfa604f9ff94df779cb9b4cbbd706258fc473ac Reviewed-on: https://go-review.googlesource.com/44150 Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
* math/big: replace local versions of bitLen, nlz with math/bits versionsRobert Griesemer2017-03-231-2/+3
| | | | | | | | | | | | Verified that BenchmarkBitLen time went down from 2.25 ns/op to 0.65 ns/op an a 2.3 GHz Intel Core i7, before removing that benchmark (now covered by math/bits benchmarks). Change-Id: I3890bb7d1889e95b9a94bd68f0bdf06f1885adeb Reviewed-on: https://go-review.googlesource.com/38464 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* all: remove the the duplicate wordsEitan Adler2017-03-061-1/+1
| | | | | | | | | Change-Id: I6343c162e27e2e492547c96f1fc504909b1c03c0 Reviewed-on: https://go-review.googlesource.com/37793 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* math/big: avoid allocation in float.{Add, Sub} when there's no aliasingAlberto Donizetti2016-08-171-12/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | name old time/op new time/op delta FloatAdd/10-4 116ns ± 1% 82ns ± 0% -28.74% (p=0.008 n=5+5) FloatAdd/100-4 124ns ± 0% 86ns ± 1% -30.34% (p=0.016 n=4+5) FloatAdd/1000-4 192ns ± 1% 123ns ± 0% -35.94% (p=0.008 n=5+5) FloatAdd/10000-4 826ns ± 0% 438ns ± 0% -46.99% (p=0.000 n=4+5) FloatAdd/100000-4 6.82µs ± 1% 3.36µs ± 0% -50.74% (p=0.008 n=5+5) FloatSub/10-4 108ns ± 1% 77ns ± 1% -29.06% (p=0.008 n=5+5) FloatSub/100-4 115ns ± 0% 79ns ± 0% -31.48% (p=0.029 n=4+4) FloatSub/1000-4 168ns ± 0% 99ns ± 0% -41.09% (p=0.029 n=4+4) FloatSub/10000-4 690ns ± 2% 288ns ± 1% -58.24% (p=0.008 n=5+5) FloatSub/100000-4 5.37µs ± 1% 2.10µs ± 1% -60.89% (p=0.008 n=5+5) name old alloc/op new alloc/op delta FloatAdd/10-4 48.0B ± 0% 0.0B ±NaN% -100.00% (p=0.008 n=5+5) FloatAdd/100-4 64.0B ± 0% 0.0B ±NaN% -100.00% (p=0.008 n=5+5) FloatAdd/1000-4 176B ± 0% 0B ±NaN% -100.00% (p=0.008 n=5+5) FloatAdd/10000-4 1.41kB ± 0% 0.00kB ±NaN% -100.00% (p=0.008 n=5+5) FloatAdd/100000-4 13.6kB ± 0% 0.0kB ±NaN% -100.00% (p=0.008 n=5+5) FloatSub/10-4 48.0B ± 0% 0.0B ±NaN% -100.00% (p=0.008 n=5+5) FloatSub/100-4 64.0B ± 0% 0.0B ±NaN% -100.00% (p=0.008 n=5+5) FloatSub/1000-4 176B ± 0% 0B ±NaN% -100.00% (p=0.008 n=5+5) FloatSub/10000-4 1.41kB ± 0% 0.00kB ±NaN% -100.00% (p=0.008 n=5+5) FloatSub/100000-4 13.6kB ± 0% 0.0kB ±NaN% -100.00% (p=0.008 n=5+5) Fixes #14868 Change-Id: Ia2b8b1a8ef0868288ecb25f812b17bd03ff40d1c Reviewed-on: https://go-review.googlesource.com/23568 Reviewed-by: Robert Griesemer <gri@golang.org>
* all: remove unnecessary type conversionsMatthew Dempsky2016-04-151-2/+2
| | | | | | | | | | | | | cmd and runtime were handled separately, and I'm intentionally skipped syscall. This is the rest of the standard library. CL generated mechanically with github.com/mdempsky/unconvert. Change-Id: I9e0eff886974dedc37adb93f602064b83e469122 Reviewed-on: https://go-review.googlesource.com/22104 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
* math/big: much simplified and faster Float roundingRobert Griesemer2016-03-221-85/+49
| | | | | | Change-Id: Iab0add7aee51a8c72a81f51d980d22d2fd612f5c Reviewed-on: https://go-review.googlesource.com/20817 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: fix rounding to smallest denormal for Float.Float32/64Robert Griesemer2016-03-211-56/+78
| | | | | | | | | | | | | | | | | Converting a big.Float value x to a float32/64 value did not correctly round x up to the smallest denormal float32/64 if x was smaller than the smallest denormal float32/64, but larger than 0.5 of a smallest denormal float32/64. Handle this case explicitly and simplify some code in the turn. For #14651. Change-Id: I025e24bf8f0e671581a7de0abf7c1cd7e6403a6c Reviewed-on: https://go-review.googlesource.com/20816 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: use correct precision in Float.Float32/64 for denormalsRobert Griesemer2016-03-041-10/+14
| | | | | | | | | | | | | When a big.Float is converted to a denormal float32/64, the rounding precision depends on the size of the denormal. Rounding may round up and thus change the size (exponent) of the denormal. Recompute the correct precision again for correct placement of the mantissa. Fixes #14553. Change-Id: Iedab5810a2d2a405cc5da28c6de7be34cb035b86 Reviewed-on: https://go-review.googlesource.com/20198 Reviewed-by: Alan Donovan <adonovan@google.com>
* all: fix typos and spellingMartin Möhrmann2016-02-241-1/+1
| | | | | | | | Change-Id: Icd06d99c42b8299fd931c7da821e1f418684d913 Reviewed-on: https://go-review.googlesource.com/19829 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* math/big: fix typoBrad Fitzpatrick2015-12-091-1/+1
| | | | | | | | Found by github user asukakenji. Change-Id: I4c76316b69e8a243fb6bf280283f3722e728d853 Reviewed-on: https://go-review.googlesource.com/17641 Reviewed-by: Robert Griesemer <gri@golang.org>
* math/big: fix SetMantExp commentDavid Crawshaw2015-10-231-1/+1
| | | | | | Change-Id: If30cf9c94b58e18564db46c15c6f5cc14ec1a6fa Reviewed-on: https://go-review.googlesource.com/16271 Reviewed-by: Robert Griesemer <gri@golang.org>
* all: use one 'l' when cancelling everywhere except SolarisRob Pike2015-09-111-1/+1
| | | | | | | | | | Fixes #11626. Change-Id: I1b70c0844473c3b57a53d7cca747ea5cdc68d232 Reviewed-on: https://go-review.googlesource.com/14526 Run-TryBot: Rob Pike <r@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* all: minor documentation tweaks for constantsKonstantin Shaposhnikov2015-09-091-1/+1
| | | | | | | | | Block comments appear after a block in the HTML documentation generated by godoc. Words like "following" should be avoided. Change-Id: Iedfad67f4b8b9c84f128b98b9b06fa76919af388 Reviewed-on: https://go-review.googlesource.com/14357 Reviewed-by: Rob Pike <r@golang.org>
* all: link to https for golang subdomains tooBrad Fitzpatrick2015-07-121-1/+1
| | | | | | | | | The previous commit (git 2ae77376) just did golang.org. This one includes golang.org subdomains like blog, play, and build. Change-Id: I4469f7b307ae2a12ea89323422044e604c5133ae Reviewed-on: https://go-review.googlesource.com/12071 Reviewed-by: Rob Pike <r@golang.org>
* math/big: turn off debug modeRobert Griesemer2015-06-031-1/+1
| | | | | | Change-Id: Ie38742cddc5a256e2f0fc0f720c0ed2f1b2e1bca Reviewed-on: https://go-review.googlesource.com/10664 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: remove (*Float).Scan, ScanFloat; more robust (*Float).ParseRobert Griesemer2015-05-291-5/+2
| | | | | | | | | | | | | | | | | | | - (*Float).Scan conflicted with fmt.Scanner.Scan; it was also only used internally. Removed it, as well as the companion ScanFloat function. - (*Float).Parse (and thus ParseFloat) can now also parse infinities. As a result, more code could be simplified. - Fixed a bug in rounding (round may implicitly be called for infinite values). Found via existing test cases, after simplifying some code. - Added more test cases. Fixes issue #10938. Change-Id: I1df97821654f034965ba8b82b272e52e6dc427f1 Reviewed-on: https://go-review.googlesource.com/10498 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: rename (*Float).Format to (*Float).TextRobert Griesemer2015-05-291-1/+1
| | | | | | | | | | | This paves the way for a fmt-compatible (*Float).Format method. A better name then Text is still desirable (suggestions welcome). This is partly fixing issue #10938. Change-Id: I59c20a8cee11f5dba059fe0f38b414fe75f2ab13 Reviewed-on: https://go-review.googlesource.com/10493 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: more cleanups (msbxx, nlzxx functions)Robert Griesemer2015-05-271-38/+38
| | | | | | Change-Id: Ibace718452b6dc029c5af5240117f5fc794c38cf Reviewed-on: https://go-review.googlesource.com/10388 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: Always print exponent sign when using 'p' exponent for Floats.Robert Griesemer2015-05-221-0/+2
| | | | | | | | | | | | | | | Float.Format supports the 'b' and 'p' format, both of which print a binary ('p') exponent. The 'b' format always printed a sign ('+' or '-') for the exponent; the 'p' format only printed a negative sign for the exponent. This change makes the two consistent. It also makes the 'p' format easier to read if the exponent is >= 0. Also: - Comments added elsewhere. Change-Id: Ifd2e01bdafb3043345972ca22a90248d055bd29b Reviewed-on: https://go-review.googlesource.com/10359 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: fix Float.Float64 conversion for denormal corner casesRobert Griesemer2015-05-221-36/+38
| | | | | | | | | | | - This change uses the same code as for Float32 and fixes the case of a number that gets rounded up to the smallest denormal. - Enabled correspoding test case. Change-Id: I8aac874a566cd727863a82717854f603fbdc26c6 Reviewed-on: https://go-review.googlesource.com/10352 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: fix Float.Float32 conversion for denormal corner casesRobert Griesemer2015-05-221-36/+43
| | | | | | | | | | | | | | | | | | | The existing code was incorrect for numbers that after rounding would become the smallest denormal float32 (instead the result was 0). This caused all.bash to fail if Float32() were used in the compiler for constant arithmetic (there's currently a work-around - see also issue 10321. This change fixes the implementation of Float.Float32 and adds corresponding test cases. Float32 and Float64 diverge at this point. For ease of review, this change only fixes Float32. Float64 will be made to match in a subsequent change. Fixes #10321. Change-Id: Iccafe37c1593a4946bc552e4ad2045f69be62d80 Reviewed-on: https://go-review.googlesource.com/10350 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: better doc strings for ErrNaN functionalityRobert Griesemer2015-04-091-3/+2
| | | | | | Change-Id: Ia0944e7b47193465d3ec37fc8dc46dea9b5dcc6b Reviewed-on: https://go-review.googlesource.com/8710 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* math/big: make ErrNaN actually implement the error interface (oversight)Robert Griesemer2015-04-081-0/+5
| | | | | | | | There was no way to get to the error message before. Change-Id: I4aa9d3d9f468c33f9996295bafcbed097de0389f Reviewed-on: https://go-review.googlesource.com/8660 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: implement missing special cases for binary operationsRobert Griesemer2015-04-021-95/+136
| | | | | | Change-Id: I9fc12b1a9b1554523e08839c1ff46c8668217ba1 Reviewed-on: https://go-review.googlesource.com/8381 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: remove NaN support - just not worth itRobert Griesemer2015-03-311-141/+79
| | | | | | | | | | | | | | | | | NaNs make the API more complicated for no real good reasons. There are few operations that produce NaNs with IEEE arithmetic, there's no need to copy the behavior. It's easy to test for these scenarios and avoid them (on the other hand, it's not easy to test for overflow or underflow, so we want to keep +/-Inf). Also: - renamed IsNeg -> Signbit (clearer, especially for x == -0) - removed IsZero (Sign() == 0 is sufficient and efficient) - removed IsFinite (now same as !IsInf) Change-Id: I3f3b4445c325d9bbb1bf46ce2e298a6aeb498e07 Reviewed-on: https://go-review.googlesource.com/8280 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: fixed Float.Float64, implemented Float.Float32Robert Griesemer2015-03-311-35/+163
| | | | | | | | | | - fix bounds checks for exponent range of denormalized numbers - use correct rounding precision for denormalized numbers - added extra tests Change-Id: I6be56399afd0d9a603300a2e44b5539e08d6f592 Reviewed-on: https://go-review.googlesource.com/8096 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: fix known bug in Float.Float64Robert Griesemer2015-03-241-13/+58
| | | | | | | | | | - handle exponent over- and underflow - handle denormalized numbers - added test cases Change-Id: I1bbb9904b0c104f54696944e1f57559881f6eeeb Reviewed-on: https://go-review.googlesource.com/7982 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: cleaner handling of exponent under/overflowRobert Griesemer2015-03-171-102/+100
| | | | | | | | Fixed several corner-case bugs and added corresponding tests. Change-Id: I23096b9caeeff0956f65ab59fa91e168d0e47bb8 Reviewed-on: https://go-review.googlesource.com/7001 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: wrap Float.Cmp result in struct to prevent wrong useRobert Griesemer2015-03-141-13/+18
| | | | | | | | | | | | | | | | | Float.Cmp used to return a value < 0, 0, or > 0 depending on how arguments x, y compared against each other. With the possibility of NaNs, the result was changed into an Accuracy (to include Undef). Consequently, Float.Cmp results could still be compared for (in-) equality with 0, but comparing if < 0 or > 0 would provide the wrong answer w/o any obvious notice by the compiler. This change wraps Float.Cmp results into a struct and accessors are used to access the desired result. This prevents incorrect use. Change-Id: I34e6a6c1859251ec99b5cf953e82542025ace56f Reviewed-on: https://go-review.googlesource.com/7526 Reviewed-by: Rob Pike <r@golang.org>
* math/big: fix minor documentation issueRobert Griesemer2015-03-131-1/+1
| | | | | | Change-Id: Ib42f75c03573cec16801b79a6eb9b1b542028f4f Reviewed-on: https://go-review.googlesource.com/7524 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: fix silly bug in Int64 accessorRobert Griesemer2015-03-131-1/+1
| | | | | | Change-Id: If335d45ea1ab6c8aeeb47515f97680e2c1d651f3 Reviewed-on: https://go-review.googlesource.com/7522 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: handle NaNs in Float.CmpRobert Griesemer2015-03-121-39/+56
| | | | | | | | | | | | | Also: - Implemented NewFloat convenience factory function (analogous to NewInt and NewRat). - Implemented convenience accessors for Accuracy values returned from Float.Cmp. - Added test and example. Change-Id: I985bb4f86e6def222d4b2505417250d29a39c60e Reviewed-on: https://go-review.googlesource.com/6970 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: added (internal) Float.form field for easier case distinctionsRobert Griesemer2015-03-121-312/+329
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a fairly significant _internal_ representation change. Instead of encoding 0, finite, infinite, and NaN values with special mantissa and exponent values, a new (1 byte) 'form' field is used (without making the Float struct bigger). The form field permits simpler and faster case distinctions. As a side benefit, for zero and non-finite floats, fewer fields need to be set. Also, the exponent range is not the full int32 range (in the old format, infExp and nanExp were used to represent Inf and NaN values and tests for those values sometimes didn't test for the empty mantissa, so the range was reduced by 2 values). The correspondence between the old and new fields is as follows. Old representation: x neg mant exp --------------------------------------------------------------- +/-0 sign empty 0 0 < |x| < +Inf sign mantissa exponent +/-Inf sign empty infExp NaN false empty nanExp New representation (- stands for ignored fields): x neg mant exp form --------------------------------------------------------------- +/-0 sign - - zero 0 < |x| < +Inf sign mantissa exponent finite +/-Inf sign - - inf NaN - - - nan Client should not be affected by this change. Change-Id: I7e355894d602ceb23f9ec01da755fe6e0386b101 Reviewed-on: https://go-review.googlesource.com/6870 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: make validate a method of Float (cleanup)Robert Griesemer2015-03-121-25/+25
| | | | | | Change-Id: If38f45acffd352ed95f32f3a36edd91a1fb33d0c Reviewed-on: https://go-review.googlesource.com/6850 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: introduce Bits abstraction instead of using "untyped" []int bit listsRobert Griesemer2015-03-121-1/+1
| | | | | | Change-Id: I6caa6bdcf6643ce3015244397a752bd133f3d00c Reviewed-on: https://go-review.googlesource.com/6840 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: reenable TestFloatAdd32 (used to fail on 32bit platforms)Robert Griesemer2015-03-041-6/+6
| | | | | | Change-Id: I932c2f1b1d27c437722cd27d2001b085a655c572 Reviewed-on: https://go-review.googlesource.com/6722 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: use stringer for enum String() methodsRobert Griesemer2015-03-041-103/+78
| | | | | | Change-Id: Ide0615542d67b7d81bf6c56aab550e142a8789f7 Reviewed-on: https://go-review.googlesource.com/6682 Reviewed-by: Alan Donovan <adonovan@google.com>
* math/big: added Float.Add example, remove warning from FloatsRobert Griesemer2015-03-041-5/+0
| | | | | | Change-Id: If04840c34b0ac5168ce1699eae880f04ae21c84c Reviewed-on: https://go-review.googlesource.com/6680 Reviewed-by: Alan Donovan <adonovan@google.com>