]> Cypherpunks repositories - gostls13.git/commit
math/big: added (internal) Float.form field for easier case distinctions
authorRobert Griesemer <gri@golang.org>
Thu, 5 Mar 2015 01:00:41 +0000 (17:00 -0800)
committerRobert Griesemer <gri@golang.org>
Thu, 12 Mar 2015 18:41:45 +0000 (18:41 +0000)
commit363617c7d3afdc9df3caf49a240679d6b6c7cc4b
tree80524a7551907793d0cf27e671a43a021fab2733
parent0ff7c3ea458dc9162333efa5ffd1ff9dccfd4fe8
math/big: added (internal) Float.form field for easier case distinctions

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>
src/math/big/decimal.go
src/math/big/float.go
src/math/big/float_test.go
src/math/big/floatconv.go
src/math/big/ftoa.go