Quantcast
Channel: Why does Math.min() return positive infinity, while Math.max() returns negative infinity? - Stack Overflow
Browsing all 11 articles
Browse latest View live

Answer by AakashM for Why does Math.min() return positive infinity, while...

It's tricky, but important, to decide correctly what aggregate functions should do when passed the empty set.Sometimes it's 'intuitively obvious': What is the SUM of no elements? Zero, I'm sure...

View Article



Answer by AVee for Why does Math.min() return positive infinity, while...

Theoretically the outcome of those functions is can't be given. The Ecma specification dictates the outcome of the Min and Max functions without arguments (See page 163). Obviously you can have all...

View Article

Answer by Juho Östman for Why does Math.min() return positive infinity, while...

It's the same reason why the sum of an empty list is usually defined as 0 and their product as 1: it is the identity element of the operation. That is, whenever you include -Infinity as an element when...

View Article

Answer by Lightness Races in Orbit for Why does Math.min() return positive...

[ECMA-262: 15.8.2.11]:max ( [ value1 [ , value2 [ , ... ] ] ] )Given zero or more arguments, calls ToNumber on each of the arguments and returns the largest of the resulting values.If no arguments are...

View Article

Answer by Matt for Why does Math.min() return positive infinity, while...

Why does it do this?Because thats what the standard says should happen;15.8.2.11 max ( [ value1 [ , value2 [ , … ] ] ] )Given zero or more arguments, calls ToNumber on each of the arguments and returns...

View Article


Answer by Shamim Hafiz - MSFT for Why does Math.min() return positive...

The idea is, mathematically without any parameter you actually have an undefined value for the minimum. As for implementation wise, usually the min value is initialized with a very large...

View Article

Answer by Divya for Why does Math.min() return positive infinity, while...

I don't know for sure. But, just making a guess.Remember how we find the min. Declare a variable with an extremely high value (Infinity) and then go through the values and whenever you find a value...

View Article

Answer by KARASZI István for Why does Math.min() return positive infinity,...

Of course it would, because the start number should be Infinity for Math.min. All number that are lower than positive infinity should be the smallest from a list, if there are no smaller.And for...

View Article


Answer by visitor for Why does Math.min() return positive infinity, while...

When given no arguments, Math.min() equals infinity and Math.max() is -infinity.This is probably to ensure that any value is smaller than the minimum found so far, and larger than the maximum so far.

View Article


Answer by Richard for Why does Math.min() return positive infinity, while...

Probably because the implementation initialises an internal comparison variable to the highest (for Math.min) or lowest (for Math.max), before starting to compare against the empty arrays, and then...

View Article

Why does Math.min() return positive infinity, while Math.max() returns...

When I type in an array into the parameter of the javascript math minimum and maximum functions, it returns the correct value:console.log( Math.min( 5 ) ); // 5console.log( Math.max( 2 ) ); // 2var...

View Article
Browsing all 11 articles
Browse latest View live




Latest Images