aboutsummaryrefslogtreecommitdiff
path: root/src/math/big/float.go
AgeCommit message (Collapse)Author
2015-03-13math/big: fix minor documentation issueRobert Griesemer
Change-Id: Ib42f75c03573cec16801b79a6eb9b1b542028f4f Reviewed-on: https://go-review.googlesource.com/7524 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-13math/big: fix silly bug in Int64 accessorRobert Griesemer
Change-Id: If335d45ea1ab6c8aeeb47515f97680e2c1d651f3 Reviewed-on: https://go-review.googlesource.com/7522 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-12math/big: handle NaNs in Float.CmpRobert Griesemer
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>
2015-03-12math/big: added (internal) Float.form field for easier case distinctionsRobert Griesemer
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>
2015-03-12math/big: make validate a method of Float (cleanup)Robert Griesemer
Change-Id: If38f45acffd352ed95f32f3a36edd91a1fb33d0c Reviewed-on: https://go-review.googlesource.com/6850 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-12math/big: introduce Bits abstraction instead of using "untyped" []int bit listsRobert Griesemer
Change-Id: I6caa6bdcf6643ce3015244397a752bd133f3d00c Reviewed-on: https://go-review.googlesource.com/6840 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-04math/big: reenable TestFloatAdd32 (used to fail on 32bit platforms)Robert Griesemer
Change-Id: I932c2f1b1d27c437722cd27d2001b085a655c572 Reviewed-on: https://go-review.googlesource.com/6722 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-04math/big: use stringer for enum String() methodsRobert Griesemer
Change-Id: Ide0615542d67b7d81bf6c56aab550e142a8789f7 Reviewed-on: https://go-review.googlesource.com/6682 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-04math/big: added Float.Add example, remove warning from FloatsRobert Griesemer
Change-Id: If04840c34b0ac5168ce1699eae880f04ae21c84c Reviewed-on: https://go-review.googlesource.com/6680 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-04math/big: remove Float.Lsh/Rsh; added shift exampleRobert Griesemer
Shifts are trivially implemented by combining Float.MantExp and Float.SetMantExp. Change-Id: Ia2fb49297d8ea7aa7d64c8b1318dc3dc7c8af2f7 Reviewed-on: https://go-review.googlesource.com/6671 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-04math/big: introduce Undef Accuracy, use for NaN operands/resultsRobert Griesemer
This change represents Accuracy as a bit pattern rather than an ordered value; with a new value Undef which is both Below and Above. Change-Id: Ibb96294c1417fb3cf2c3cf2374c993b0a4e106b3 Reviewed-on: https://go-review.googlesource.com/6650 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-04math/big: modified MantExp semantics to enable fast exponent accessRobert Griesemer
Change-Id: I9a6ebb747d5b9756c214bdeb19f60820602d7a24 Reviewed-on: https://go-review.googlesource.com/6340 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-04math/big: implement NaNRobert Griesemer
This change introduces NaNs (for situations like Inf-Inf, etc.). The implementation is incomplete (the four basic operations produce a NaN if any of the operands is an Inf or a NaN); and some operations produce incorrect accuracy for NaN arguments. These are known bugs which are documented. Change-Id: Ia88841209e47930681cef19f113e178f92ceeb33 Reviewed-on: https://go-review.googlesource.com/6540 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-02math/big: replace Float.NewInf with Float.SetInf for more consistent APIRobert Griesemer
Change-Id: I2a60ea4a196eef1af5d2aae6cc239c64bddb6fb2 Reviewed-on: https://go-review.googlesource.com/6301 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-26math/big: export Float.MinPrecRobert Griesemer
MinPrec returns the minimum precision required to represent a Float without loss of precision. Added test. Change-Id: I466c8e492dcdd59fae854fc4e71ef9b1add7d817 Reviewed-on: https://go-review.googlesource.com/6010 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-25math/big: clean up Float.SetPrec, use shorter internal representationRobert Griesemer
Change-Id: I9b78085adc12cbd240d0b8b48db6810ddb2aeadd Reviewed-on: https://go-review.googlesource.com/5991 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-25math/big: apply a round of go vetRobert Griesemer
Change-Id: Ie8310acc783659497e50dfe629f06d655b51d647 Reviewed-on: https://go-review.googlesource.com/5990 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-25math/big: improve some doc stringsRobert Griesemer
Change-Id: Ie37673d4af2fa7476d67ffb686641611ab6a8e6b Reviewed-on: https://go-review.googlesource.com/5930 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-25math/big: permit passing of an *Int to Float.Int to avoid allocationRobert Griesemer
Change-Id: I50e83248357928e56c94b88a8764de828f4f5c76 Reviewed-on: https://go-review.googlesource.com/5890 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-25math/big: implemented Float.RatRobert Griesemer
Change-Id: If516e12d4b5dfb6f9288437d270569f7e4e2a1cd Reviewed-on: https://go-review.googlesource.com/5871 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-25math/big: permit passing of (possibly nil) *Float to MantExp to avoid allocationRobert Griesemer
Change-Id: Ia92eea833283f8b16fa09d4ca1c9cb3bc0eb18a2 Reviewed-on: https://go-review.googlesource.com/5870 Reviewed-by: Rob Pike <r@golang.org>
2015-02-24math/big: change Float.SetMantExp to always multiply mant by 2**expRobert Griesemer
Change-Id: If840e647376a2141f8c17729f7ef251bfff13f5f Reviewed-on: https://go-review.googlesource.com/5810 Reviewed-by: Rob Pike <r@golang.org>
2015-02-24math/big: fix several issues with string->Float conversionRobert Griesemer
Change-Id: I7bf7154e2d8d779fdf7f1d2bb561a06ad174f3b0 Reviewed-on: https://go-review.googlesource.com/4883 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-23math/big: incorporated feedback from prior TBR reviewsRobert Griesemer
Change-Id: Ida847365223ef09b4a3846e240b4bb6919cb0fe9 Reviewed-on: https://go-review.googlesource.com/5610 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-15math/big: implement fast path in Float.SetRat if argument is integerRobert Griesemer
Change-Id: Ib82500e198b86e9fade278c7eea7a4b0c6b0b2e1 Reviewed-on: https://go-review.googlesource.com/4921 Reviewed-by: Rob Pike <r@golang.org>
2015-02-15math/big: always round after the sign is setRobert Griesemer
Some rounding modes are affected by the sign of the value to be rounded. Make sure the sign is set before round is called. Added tests (that failed before the fix). Change-Id: Idd09b8fcbab89894fede0b9bc922cda5ddc87930 Reviewed-on: https://go-review.googlesource.com/4876 Reviewed-by: Rob Pike <r@golang.org>
2015-02-14math/big: fix aliasing bug in Float.QuoRobert Griesemer
TBR r, adonovan Change-Id: I1a38e2d724bf1147c7307a7e5ae855c42c60428c Reviewed-on: https://go-review.googlesource.com/4875 Reviewed-by: Robert Griesemer <gri@golang.org>
2015-02-14math/big: remove Float.Round (not needed anymore), fix a bug in SetInt64Robert Griesemer
TBR adonovan Change-Id: I30020f39be9183b37275e10a4fd1e1a3b4c48c89 Reviewed-on: https://go-review.googlesource.com/4880 Reviewed-by: Robert Griesemer <gri@golang.org>
2015-02-14math/big: implement/rename accessors for precision and rounding modeRobert Griesemer
Also: remove NewFloat - not needed anymore. Work-around for places where has been used so far: NewFloat(x, prec, mode) === new(Float).SetMode(mode).SetPrec(prec).SetFloat64(x) However, if mode == ToNearestEven, SetMode is not needed. SetPrec is needed if the default precision (53 after SetFloat64) is not adequate. TBR adonovan Change-Id: Ifda12c479ba157f2dea306c32b47c7afbf31e759 Reviewed-on: https://go-review.googlesource.com/4842 Reviewed-by: Robert Griesemer <gri@golang.org>
2015-02-14math/big: fix aliasing error in Add, SubRobert Griesemer
Also: - make representation more flexible (no need to store trailing 0 digits to match precision) - simplify rounding as a consequence - minor related fixes TBR adonovan Change-Id: Ie91075990688b506d28371ec3b633b8267397ebb Reviewed-on: https://go-review.googlesource.com/4841 Reviewed-by: Rob Pike <r@golang.org>
2015-02-14math/big: use internal validation more consistentlyRobert Griesemer
TBR adonovan Change-Id: If77afa6474af6cad6512f6866725e3ae5acf2e3f Reviewed-on: https://go-review.googlesource.com/4840 Reviewed-by: Robert Griesemer <gri@golang.org>
2015-02-12math/big: implemented Float.Int64, simplified Float.Uint64Robert Griesemer
Change-Id: Ic270ffa7ec6f6dd4b0a951c64ad965447cce1417 Reviewed-on: https://go-review.googlesource.com/4571 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-11math/big: completed Float.Uint64Robert Griesemer
Change-Id: Ib3738492a2ec8fc99323e687168b17b7239db6ad Reviewed-on: https://go-review.googlesource.com/4511 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-11math/big: implemented Float.Int (truncation of Floats to Ints)Robert Griesemer
Change-Id: Id98f7333fe6ae1b64e0469c6d01f02360c1f8f55 Reviewed-on: https://go-review.googlesource.com/4481 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-11math/big: When result prec == 0, use at least prec == 64 for SetInt, SetRat.Robert Griesemer
This avoids surprises. Change-Id: Iaae67da2d12e29c4e797ad6313e0895f7ce80cb1 Reviewed-on: https://go-review.googlesource.com/4480 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-10math/big: implemented Frexp, Ldexp, IsInt, Copy, bug fixes, more testsRobert Griesemer
- Frexp, Ldexp are equivalents to the corresponding math functions. - Set now has the same prec behavior as the other functions - Copy is a true assignment (replaces old version of Set) - Cmp now handles infinities - more tests Change-Id: I0d33980c08be3095b25d7b3d16bcad1aa7abbd0f Reviewed-on: https://go-review.googlesource.com/4292 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-09math/big: correct umaxRobert Griesemer
Change-Id: I208c8ac44d1a8882d8fdeb18347dc20941e20374 Reviewed-on: https://go-review.googlesource.com/4250 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-09math/big: API cleanupRobert Griesemer
- better and more consistent documentation - more functions implemented - more tests Change-Id: If4c591e7af4ec5434fbb411a48dd0f8add993720 Reviewed-on: https://go-review.googlesource.com/4140 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-06math/big: handling of +/-Inf and zero precision, enable zero valuesRobert Griesemer
- clarified representation of +/-Inf - only 0 and Inf values can have 0 precision - a zero precision value used as result value takes the max precision of the arguments (to be fine-tuned for setters) - the zero precision approach makes Float zero values possible (they represent +0) - more tests Missing: Filling in the blanks. More tests. Change-Id: Ibb4f97e12e1f356c3085ce80f3464e97b82ac130 Reviewed-on: https://go-review.googlesource.com/4000 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-03math/big: fix typosRobert Griesemer
Change-Id: Icb1490f97584d61823339ae809b88d423b185e64 Reviewed-on: https://go-review.googlesource.com/3751 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-02-03math/big: build Float.Format on top of Float.AppendRobert Griesemer
Change-Id: I444eec24467f827caa5c88a1c5ae5bce92508b98 Reviewed-on: https://go-review.googlesource.com/3750 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-01-30math/big: split float conversion routines and tests into separate filesRobert Griesemer
No other functional changes. Change-Id: I7e0bb7452c6a265535297ec7ce6a629f1aff695c Reviewed-on: https://go-review.googlesource.com/3674 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-01-30math/big: parsing of fractions and floats in mantissa bases other than 10Robert Griesemer
Change-Id: I1eaebf956a69e0958201cc5e0a9beefa062c71e1 Reviewed-on: https://go-review.googlesource.com/3454 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-01-28math/big: sketched out complete set of Float/string conversion functionsRobert Griesemer
Also: - use io.ByteScanner rather than io.RuneScanner internally - minor simplifications in Float.Add/Sub Change-Id: Iae0e99384128dba9eccf68592c4fd389e2bd3b4f Reviewed-on: https://go-review.googlesource.com/3380 Reviewed-by: Rob Pike <r@golang.org>
2015-01-27math/big: various fixes, enable tests for 32bit platformsRobert Griesemer
- fixed Float.Add, Float.Sub - fixed Float.PString to be platform independent - fixed Float.Uint64 - fixed various test outputs TBR: adonovan Change-Id: I9d273b344d4786f1fed18862198b23285c358a39 Reviewed-on: https://go-review.googlesource.com/3321 Reviewed-by: Robert Griesemer <gri@golang.org>
2015-01-24math/big: disable some tests on 32bit platforms (fix build)Robert Griesemer
TBR: adonovan Change-Id: I59757b5b46a2c533fc5f888423c99d550d3c7648 Reviewed-on: https://go-review.googlesource.com/3264 Reviewed-by: Robert Griesemer <gri@golang.org>
2015-01-24math/big: multi-precision Floats (starting point)Robert Griesemer
Implemented: - +, -, *, /, and some unary ops - all rounding modes - basic conversions - string to float conversion - tests Missing: - float to string conversion, formatting - handling of +/-0 and +/-inf (under- and overflow) - various TODOs and cleanups With precision set to 24 or 53, the results match float32 or float64 operations exactly (excluding NaNs and denormalized numbers which will not be supported). Change-Id: I3121e90fc4b1528e40bb6ff526008da18b3c6520 Reviewed-on: https://go-review.googlesource.com/1218 Reviewed-by: Alan Donovan <adonovan@google.com>