Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

lindahua
Copy link
Contributor

With this modified implementation, we don't have to check (v != v) within inner loops.

Rationales:

  1. NaN only exist for floating points -- so only have to deal with them in methods specialized to floating point.
  2. Once a non-NaN value is found, we can then follow the normal routine. Because x > v (or x < v) is never true when x is NaN, and therefore, v won't become NaN again.

Note: I also added several test cases to ensure the correctness.

With this modified implementation, we don't have to check (v != v) within inner loops. Rationales: (1) NaN only exist for floating points -- so only have to deal with them in versions specialized to floating point. (2) Once a non-NaN value is found, we can then follow the normal routine. Because x > v (or x < v) is never true when x is NaN, and therefore, v won't become NaN again.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reverts #5031

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change that. Thanks for pointing out.

@StefanKarpinski
Copy link
Member

Excellent. This is a great change. Thanks for taking the time and effort to apply these kinds of optimizations in Base.

StefanKarpinski added a commit that referenced this pull request Dec 29, 2013
Modified implementation of maximum & minimum with improved efficiency.
@StefanKarpinski StefanKarpinski merged commit 94438e5 into JuliaLang:master Dec 29, 2013
@JeffBezanson
Copy link
Member

Yes, this is good. But I wonder if the FloatingPoint version should just be used for all types --- LLVM might be able to figure out that v!=v is always false for integers and remove the whole first loop. Even if it can't, it's just one extra branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants