]> Cypherpunks.ru repositories - gostls13.git/commitdiff
math/big: permit upper-case 'P' binary exponent (not just 'p')
authorRobert Griesemer <gri@golang.org>
Wed, 23 Jan 2019 23:36:41 +0000 (15:36 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 11 Feb 2019 23:22:35 +0000 (23:22 +0000)
The current implementation accepted binary exponents but restricted
them to 'p'. This change permits both 'p' and 'P'.

R=Go1.13

Updates #29008.

Change-Id: I7a89ccb86af4438f17b0422be7cb630ffcf43272
Reviewed-on: https://go-review.googlesource.com/c/159297
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
src/math/big/floatconv.go
src/math/big/floatconv_test.go
src/math/big/ratconv.go

index 95d1bf84e2436361c4efb06d7b0326d27cc251cc..5cc9e24f4c42e2f996a78703b85ff4de71021456 100644 (file)
@@ -224,7 +224,7 @@ func (z *Float) pow5(n uint64) *Float {
 //     sign     = "+" | "-" .
 //     prefix   = "0" ( "x" | "X" | "b" | "B" ) .
 //     mantissa = digits | digits "." [ digits ] | "." digits .
-//     exponent = ( "E" | "e" | "p" ) [ sign ] digits .
+//     exponent = ( "e" | "E" | "p" | "P" ) [ sign ] digits .
 //     digits   = digit { digit } .
 //     digit    = "0" ... "9" | "a" ... "z" | "A" ... "Z" .
 //     infinity = [ sign ] ( "inf" | "Inf" ) .
@@ -238,7 +238,7 @@ func (z *Float) pow5(n uint64) *Float {
 // The octal prefix "0" is not supported (a leading "0" is simply
 // considered a "0").
 //
-// A "p" exponent indicates a binary (rather then decimal) exponent;
+// A "p" or "P" exponent indicates a binary (rather then decimal) exponent;
 // for instance "0x1.fffffffffffffp1023" (using base 0) represents the
 // maximum float64 value. For hexadecimal mantissae, the exponent must
 // be binary, if present (an "e" or "E" exponent indicator cannot be
index 269e2652e89b032ad814c578d76835ee5a7dac7b..6db9bf2e466e4167c8329097068d6cf4e179d980 100644 (file)
@@ -108,6 +108,7 @@ func TestFloatSetFloat64String(t *testing.T) {
                {"0b001p-3", 0.125},
                {"0b.001p3", 1},
                {"0b0.01p2", 1},
+               {"0b0.01P+2", 1},
 
                // hexadecimal mantissa and exponent
                {"0x0", 0},
@@ -117,6 +118,7 @@ func TestFloatSetFloat64String(t *testing.T) {
                {"0xff", 255},
                {"0X.8p1", 1},
                {"-0X0.00008p16", -0.5},
+               {"-0X0.00008P+16", -0.5},
                {"0x0.0000000000001p-1022", math.SmallestNonzeroFloat64},
                {"0x1.fffffffffffffp1023", math.MaxFloat64},
        } {
index 5656280e84dabcfb0b7f4754c91ed8fc236692c7..bd2509f168ae6eb8d70ad1ed53adb6d9d88ea630 100644 (file)
@@ -130,10 +130,10 @@ func (z *Rat) SetString(s string) (*Rat, bool) {
 }
 
 // scanExponent scans the longest possible prefix of r representing a decimal
-// ('e', 'E') or binary ('p') exponent, if any. It returns the exponent, the
-// exponent base (10 or 2), or a read or syntax error, if any.
+// ('e', 'E') or binary ('p', 'P') exponent, if any. It returns the exponent,
+// the exponent base (10 or 2), or a read or syntax error, if any.
 //
-//     exponent = ( "E" | "e" | "p" ) [ sign ] digits .
+//     exponent = ( "e" | "E" | "p" | "P" ) [ sign ] digits .
 //     sign     = "+" | "-" .
 //     digits   = digit { digit } .
 //     digit    = "0" ... "9" .
@@ -153,7 +153,7 @@ func scanExponent(r io.ByteScanner, binExpOk bool) (exp int64, base int, err err
        switch ch {
        case 'e', 'E':
                // ok
-       case 'p':
+       case 'p', 'P':
                if binExpOk {
                        base = 2
                        break // ok