Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1085)

Issue 145650043: code review 145650043: math/big: math.Exp should return result >= 0 (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
9 years, 7 months ago by gri
Modified:
9 years, 7 months ago
Reviewers:
agl1, r, rsc
CC:
agl, agl1, r, rsc, golang-codereviews
Visibility:
Public.

Description

math/big: math.Exp should return result >= 0 for |m| > 0 The documentation states that Exp(x, y, m) computes x**y mod |m| for m != nil && m > 0. In math.big, Mod is the Euclidean modulus, which is always >= 0. Fixes issue 8822.

Patch Set 1 #

Patch Set 2 : diff -r 07bb65448c694d51ce8bba4b09102c8c04ece2e8 https://code.google.com/p/go/ #

Patch Set 3 : diff -r 07bb65448c694d51ce8bba4b09102c8c04ece2e8 https://code.google.com/p/go/ #

Total comments: 2

Patch Set 4 : diff -r 61525d46311930992512297749c1ad914912041b https://code.google.com/p/go/ #

Total comments: 4

Patch Set 5 : diff -r c361cbe8f03c802d2d1054f21447cc865dcb6d68 https://code.google.com/p/go/ #

Patch Set 6 : diff -r c361cbe8f03c802d2d1054f21447cc865dcb6d68 https://code.google.com/p/go/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+17 lines, -3 lines) Patch
M src/math/big/int.go View 1 2 3 4 1 chunk +6 lines, -0 lines 0 comments Download
M src/math/big/int_test.go View 1 2 3 3 chunks +11 lines, -3 lines 0 comments Download

Messages

Total messages: 9
gri
Hello agl@chromium.org (cc: golang-codereviews@googlegroups.com), I'd like you to review this change to https://code.google.com/p/go/
9 years, 7 months ago (2014-09-30 20:40:48 UTC) #1
agl1
LGTM https://codereview.appspot.com/145650043/diff/40001/src/math/big/int_test.go File src/math/big/int_test.go (right): https://codereview.appspot.com/145650043/diff/40001/src/math/big/int_test.go#newcode808 src/math/big/int_test.go:808: "-0x1BCE04427D8032319A89E5C4136456671AC620883F2C4139E57F91307C485AD2D6204F4F87A58262652DB5DBBAC72B0613E51B835E7153BEC6068F5C8D696B7" + nit (feel free to ignore): these ...
9 years, 7 months ago (2014-09-30 20:47:14 UTC) #2
gri
https://codereview.appspot.com/145650043/diff/40001/src/math/big/int_test.go File src/math/big/int_test.go (right): https://codereview.appspot.com/145650043/diff/40001/src/math/big/int_test.go#newcode808 src/math/big/int_test.go:808: "-0x1BCE04427D8032319A89E5C4136456671AC620883F2C4139E57F91307C485AD2D6204F4F87A58262652DB5DBBAC72B0613E51B835E7153BEC6068F5C8D696B7" + On 2014/09/30 20:47:13, agl1 wrote: > nit ...
9 years, 7 months ago (2014-09-30 20:51:48 UTC) #3
gri
9 years, 7 months ago (2014-09-30 20:53:58 UTC) #4
r
https://codereview.appspot.com/145650043/diff/60001/src/math/big/int.go File src/math/big/int.go (right): https://codereview.appspot.com/145650043/diff/60001/src/math/big/int.go#newcode608 src/math/big/int.go:608: if len(z.abs) > 0 && x.neg && len(yWords) > ...
9 years, 7 months ago (2014-09-30 21:05:32 UTC) #5
gri
https://codereview.appspot.com/145650043/diff/60001/src/math/big/int.go File src/math/big/int.go (right): https://codereview.appspot.com/145650043/diff/60001/src/math/big/int.go#newcode608 src/math/big/int.go:608: if len(z.abs) > 0 && x.neg && len(yWords) > ...
9 years, 7 months ago (2014-09-30 21:18:03 UTC) #6
r
LGTM. ask rsc.
9 years, 7 months ago (2014-09-30 21:52:13 UTC) #7
rsc
LGTM either way https://codereview.appspot.com/145650043/diff/60001/src/math/big/int.go File src/math/big/int.go (right): https://codereview.appspot.com/145650043/diff/60001/src/math/big/int.go#newcode608 src/math/big/int.go:608: if len(z.abs) > 0 && x.neg ...
9 years, 7 months ago (2014-10-02 19:04:14 UTC) #8
gri
9 years, 7 months ago (2014-10-02 20:02:35 UTC) #9
*** Submitted as https://code.google.com/p/go/source/detail?r=52bacae4f5b0 ***

math/big: math.Exp should return result >= 0 for |m| > 0

The documentation states that Exp(x, y, m)
computes x**y mod |m| for m != nil && m > 0.
In math.big, Mod is the Euclidean modulus,
which is always >= 0.

Fixes issue 8822.

LGTM=agl, r, rsc
R=agl, r, rsc
CC=golang-codereviews
https://codereview.appspot.com/145650043

https://codereview.appspot.com/145650043/diff/60001/src/math/big/int.go
File src/math/big/int.go (right):

https://codereview.appspot.com/145650043/diff/60001/src/math/big/int.go#newco...
src/math/big/int.go:608: if len(z.abs) > 0 && x.neg && len(yWords) > 0 &&
yWords[0]&1 == 1 {
On 2014/10/02 19:04:14, rsc wrote:
> On 2014/09/30 21:18:03, gri wrote:
> > On 2014/09/30 21:05:32, r wrote:
> > > deserves a comment. this is magic.
> > 
> > hence the comment just below...
> > 
> > (this kind of code is pretty common in this package)
> 
> i think you could plausibly keep the old phrasing and then frame this mod
thing
> as a fixup:
> 
> z.neg = len(z.abs) > 0 && x.neg && len(yWords) > 0 && yWords[0]&1 == 1 // 0
has
> no sign
> 
> if z.neg && len(mWords) > 0 {
>     // make modulus result positive
>     z.abs = ...
>     z.neg = false
> }
> 

Done.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b