Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Issue 10690086: Inline compareTo for numbers into min and max. (Closed)

Created:
8 years, 5 months ago by floitsch
Modified:
8 years, 5 months ago
CC:
reviews_dartlang.org
Visibility:
Public.

Description

Inline compareTo for numbers into min and max. Committed: https://code.google.com/p/dart/source/detail?r=9564

Patch Set 1 #

Total comments: 19

Patch Set 2 : Refactored. #

Total comments: 8

Patch Set 3 : Address comments. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+651 lines, -20 lines) Patch
M corelib/src/math.dart View 1 2 1 chunk +65 lines, -10 lines 0 comments Download
M lib/math/base.dart View 1 2 1 chunk +65 lines, -10 lines 0 comments Download
A tests/corelib/min_max_test.dart View 1 1 chunk +521 lines, -0 lines 0 comments Download

Messages

Total messages: 6 (0 generated)
floitsch
8 years, 5 months ago (2012-07-04 18:35:15 UTC) #1
sra1
DBC https://chromiumcodereview.appspot.com/10690086/diff/1/corelib/src/math.dart File corelib/src/math.dart (right): https://chromiumcodereview.appspot.com/10690086/diff/1/corelib/src/math.dart#newcode63 corelib/src/math.dart:63: if (a is num) { // TODO(floitsch): move ...
8 years, 5 months ago (2012-07-04 19:28:23 UTC) #2
Lasse Reichstein Nielsen
LGTM, but try the short version and see if it's faster! https://chromiumcodereview.appspot.com/10690086/diff/1/corelib/src/math.dart File corelib/src/math.dart (right): ...
8 years, 5 months ago (2012-07-05 09:34:40 UTC) #3
floitsch
Refactored the methods. Please have another look. https://chromiumcodereview.appspot.com/10690086/diff/1/corelib/src/math.dart File corelib/src/math.dart (right): https://chromiumcodereview.appspot.com/10690086/diff/1/corelib/src/math.dart#newcode63 corelib/src/math.dart:63: if (a ...
8 years, 5 months ago (2012-07-05 17:48:49 UTC) #4
Lasse Reichstein Nielsen
There is also a math library in lib/math/base.dart that should also be updated. LGTM. https://chromiumcodereview.appspot.com/10690086/diff/6001/corelib/src/math.dart ...
8 years, 5 months ago (2012-07-10 07:35:00 UTC) #5
floitsch
8 years, 5 months ago (2012-07-10 17:32:32 UTC) #6
https://chromiumcodereview.appspot.com/10690086/diff/6001/corelib/src/math.dart
File corelib/src/math.dart (right):

https://chromiumcodereview.appspot.com/10690086/diff/6001/corelib/src/math.da...
corelib/src/math.dart:62: static num min(num a, num b) {
On 2012/07/10 07:35:00, Lasse Reichstein Nielsen wrote:
> Give it a doc-comment and say how it works (NaN if either value is NaN, -0.0 <
> 0.0, otherwise int/double with same mathematical value are equal). And that if
> they are equal, you return the first argument (but I'd prefer documenting it
as
> being unspecified which one is returned).

Done.

https://chromiumcodereview.appspot.com/10690086/diff/6001/corelib/src/math.da...
corelib/src/math.dart:77: return (a + b) * a * b;
On 2012/07/10 07:35:00, Lasse Reichstein Nielsen wrote:
> This should work even if a or b are not doubles. At least you can remove the
'a
> is double' check.
> If you inserted it for performance, not correctness, do say so.

I want to return a consistent order when both arguments are equal. Without the
check min(0, 0.0) would return 0.0, but min(1, 1.0) would return 1.

https://chromiumcodereview.appspot.com/10690086/diff/6001/corelib/src/math.da...
corelib/src/math.dart:80: // Check for NaN and b == -0.0.
On 2012/07/10 07:35:00, Lasse Reichstein Nielsen wrote:
> If you didn't check for "a is double" above, then b==NaN would be handled
there.
Yes, but then we wouldn't return the left argument.

https://chromiumcodereview.appspot.com/10690086/diff/6001/corelib/src/math.da...
corelib/src/math.dart:109: // Check for NaN.
On 2012/07/10 07:35:00, Lasse Reichstein Nielsen wrote:
> Don't we have b.isNaN()? I'd prefer using that, at least for readability.

Done.

Powered by Google App Engine
This is Rietveld 408576698