We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
If clamp is given NaN as third argument it should return it unchanged, but instead it returns the given upper limit:
clamp
NaN
elm repl > clamp -100 100 (0/0) 100 : Float
I don't understand why this happens. clamp is defined as (source)
clamp : number -> number -> number -> number clamp low high number = if lt number low then low else if gt number high then high else number
Since both comparisons should be False, number should be returned unchanged, but that doesn't happen.
False
number
I can't test gt myself, but its corresponding > does return False as expected:
gt
>
elm repl > (0/0) > 100 False : Bool
Maybe related to #1050
The text was updated successfully, but these errors were encountered:
Thanks for reporting this! To set expectations:
Finally, please be patient with the core team. They are trying their best with limited resources.
Sorry, something went wrong.
Basics.clamp is compiled to:
Basics.clamp
var $elm$core$Basics$clamp = F3( function (low, high, number) { return (_Utils_cmp(number, low) < 0) ? low : ((_Utils_cmp(number, high) > 0) ? high : number); });
and because _Utils_cmp does:
_Utils_cmp
function _Utils_cmp(x, y, ord) { if (typeof x !== 'object') { return x === y ? /*EQ*/ 0 : x < y ? /*LT*/ -1 : /*GT*/ 1; }
with both x === y and x < y returning false with NaN, it will return GT, therefore the clamp higher value will be returned:
x === y
x < y
false
GT
> Basics.compare (0/0) 100 GT : Order
(>) (0/0) 100 returns False because it is optimized by the compiler to (0 / 0) > 100 in javascript without using _Utils_cmp.
(>) (0/0) 100
(0 / 0) > 100
If you trick the compiler to avoid the optimization, you get True for NaN > 100:
True
NaN > 100
> (>) (0/0) 100 False : Bool > gt = (>) <function> : comparable -> comparable -> Bool > gt (0/0) 100 True : Bool
No branches or pull requests
If
clamp
is givenNaN
as third argument it should return it unchanged, but instead it returns the given upper limit:I don't understand why this happens.
clamp
is defined as (source)Since both comparisons should be
False
,number
should be returned unchanged, but that doesn't happen.I can't test
gt
myself, but its corresponding>
does returnFalse
as expected:Maybe related to #1050
The text was updated successfully, but these errors were encountered: