Comments (15)
This comment was originally written by [email protected]
Here's a patch with an implementation and tests.
Attachment:
clamp.diff (1.36 KB)
from sdk.
This comment was originally written by [email protected]
What should happen if lower >= upper?
from sdk.
This comment was originally written by [email protected]
Removed Type-Defect label.
Added Type-Enhancement label.
from sdk.
This comment was originally written by [email protected]
It should probably throw an exception like the functions in Date do.
Side note: should the docs for Expect.throws() mention the () => foo() syntax? I at least had to poke around for a bit to figure it out.
Attachment:
clamp_v2.diff (1.51 KB)
from sdk.
This comment was originally written by [email protected]
Added Area-Language, Triaged labels.
from sdk.
This comment was originally written by [email protected]
It's probably worth noting here that this idea was received pretty warmly over on Reddit. http://www.reddit.com/r/programming/comments/l6uwv/dart_programming_language/c2q9sbc
from sdk.
Removed Area-Language label.
Added Area-Library label.
from sdk.
We are discussing the idea. Currently we are tending towards adding it to the num interface. Ex:
x.clamp(1, 3);
instead of
Math.clamp(x, 1, 3);
from sdk.
This comment was originally written by [email protected]
I don't see if lower = upper as an issue. Just return lower or upper, which is almost certainly what the programmer would want. If lower > upper, than it would make sence to which lower and upper around. Although this is probably the best thing to do hear in terms of the programmers intentions, this would degrade performance(no more than throwing an exception would however).
from sdk.
This comment was originally written by [email protected]
My vote agrees with Comment #8. Sorry if this is considered a "Me too".. I'd like the ability to just Star a comment. :-\
from sdk.
Also would be good to get nearlyEquals from goog.math:
http://code.google.com/p/closure-library/source/browse/trunk/closure/goog/math/math.js
from sdk.
cc @lrhn.
Added this to the Later milestone.
from sdk.
This comment was originally written by [email protected]
@clamp_v2.diff
"if (lower >= upper) throw new IllegalArgumentException();"
That should be '>', not '>='. Using the same value for both is seemingly pointless, but it's not illegal. E.g. if you want that your 5 is at least 5 and at most 5, then, yes, you can have that totally five-y 5.
It really isn't as stupid as it sounds, seriously. Imagine there is a range slider which doesn't enforce a minimum distance between both values and you just take those values and throw them at this clamp function. Would be nice if it would work, wouldn't it?
Well, with "Math.max(Math.min(val, atLeast), atMost)" this works just fine. Naturally, it should work with a built-in clamp function, too.
from sdk.
Set owner to @floitschG.
Added Started label.
from sdk.
Fixed in lib_v2, r14576.
Added Fixed label.
from sdk.
Related Issues (20)
- `ConstructorDefinitionBuilder.augment` cannot augment factory constructor
- [vm] Dart AOT runtime should refuse to run snapshots with incompatible sanitizers HOT 2
- [vm] gen_snapshot without santizers should be able to create AOT snapshots to be used with AOT runtimes with sanitizers HOT 1
- [CRASH] `dart run` fails logging `Compilation did not produce any result...` and crashes with `PathNotFoundException` HOT 5
- allow to destructure record types with positional fields HOT 8
- [analyzer] add warning when abstract interface class has unused implementation.
- [analyzer] incorrectly marking as dead code when accessing record property in ternary
- Breakpoints skipped in tests when injecting late initialized dependency. HOT 2
- Function argument rejected based on faulty inferred parameter type
- AOT compilation runs into speculative input use by `CalculateElementAddressInstr` HOT 1
- Analyzer Feedback from IntelliJ
- Type inference for abstract classes with recurring generics can't be inferred HOT 9
- The front end is not happy about wrong constructor declaration
- The front end is not happy about wrong extension type constructor declaration
- pkg/analyzer/test/src/dart/resolution/augmented_invocation_test fails with RuntimeError on analyzer-asserts-win bot HOT 2
- Code completion suggestions are irrelevant / context unaware HOT 2
- [Wildcard Variables] Language Tests in `tests/language` HOT 3
- [Wildcard Variables] All tests in `tests/language` and co19 passing.
- [Wildcard Variables] Experiment Flag HOT 2
- [Wildcard Variables] CFE Implementation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdk.