• Robert Griesemer's avatar
    go/constant: switch to floating-point representation when fractions become too large · d0c17461
    Robert Griesemer authored
    Use two internal representations for Float values (similar to what is done
    for Int values). Transparently switch to a big.Float representation when
    big.Rat values become unwieldy. This is almost never needed for real-world
    programs but it is trivial to create test cases that cannot be handled with
    rational arithmetic alone.
    
    As a consequence, the go/constant API semantics changes slightly: Until now,
    a value could always be represented in its "smallest" form (e.g., float values
    that happened to be integers would be represented as integers). Now, constant
    Kind depends on how the value was created, rather than its actual value. (The
    reason why we cannot automatically "normalize" values to their smallest form
    anymore is because floating-point numbers are not exact in general; and thus
    normalization is often not possible in the first place, or would throw away
    precision when it is not desired.) This has repercussions as to how constant
    Values are used go/types and required corresponding adjustments.
    
    Details of the changes:
    
    go/constant package:
    - use big.Rat and big.Float values to represent floating-point values
      (internal change)
    - changed semantic of Value.Kind accordingly
    - String now returns a short, human-readable form of a value
      (this leads to better error messages in go/types)
    - added ToInt, ToFloat, and ToComplex conversion functions
    - added ExactString to obtain an exact string form of a value
    
    go/types:
    - adjusted and simplified implementation of representableConst
    - adjusted various places where Value.Kind was expected to be "smallest"
      by calling the respective ToInt/Float/Complex conversion functions
    - enabled 5 disabled tests in stdlib_test.go that now work
    
    api checker:
    - print all constant values in a short human-readable form (floats are
      printed in floating-point form), but also print an exact form if it
      is different from the short form
    - adjusted test golden file and go.1.1.text reference file
    
    Fixes #11327.
    
    Change-Id: I492b704aae5b0238e5b7cee13e18ffce61193587
    Reviewed-on: https://go-review.googlesource.com/17360Reviewed-by: 's avatarAlan Donovan <adonovan@google.com>
    Run-TryBot: Robert Griesemer <gri@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    d0c17461
Name
Last commit
Last update
..
archive Loading commit data...
bufio Loading commit data...
builtin Loading commit data...
bytes Loading commit data...
cmd Loading commit data...
compress Loading commit data...
container Loading commit data...
crypto Loading commit data...
database/sql Loading commit data...
debug Loading commit data...
encoding Loading commit data...
errors Loading commit data...
expvar Loading commit data...
flag Loading commit data...
fmt Loading commit data...
go Loading commit data...
hash Loading commit data...
html Loading commit data...
image Loading commit data...
index/suffixarray Loading commit data...
internal Loading commit data...
io Loading commit data...
log Loading commit data...
math Loading commit data...
mime Loading commit data...
net Loading commit data...
os Loading commit data...
path Loading commit data...
reflect Loading commit data...
regexp Loading commit data...
runtime Loading commit data...
sort Loading commit data...
strconv Loading commit data...
strings Loading commit data...
sync Loading commit data...
syscall Loading commit data...
testing Loading commit data...
text Loading commit data...
time Loading commit data...
unicode Loading commit data...
unsafe Loading commit data...
vendor/golang.org/x/net/http2/hpack Loading commit data...
Make.dist Loading commit data...
all.bash Loading commit data...
all.bat Loading commit data...
all.rc Loading commit data...
androidtest.bash Loading commit data...
bootstrap.bash Loading commit data...
buildall.bash Loading commit data...
clean.bash Loading commit data...
clean.bat Loading commit data...
clean.rc Loading commit data...
iostest.bash Loading commit data...
make.bash Loading commit data...
make.bat Loading commit data...
make.rc Loading commit data...
nacltest.bash Loading commit data...
race.bash Loading commit data...
race.bat Loading commit data...
run.bash Loading commit data...
run.bat Loading commit data...
run.rc Loading commit data...