'Javascript: calculate average of MAX_VALUE

The testing environment passes the following arguments to my getAverage function:

assert.equal(tasks.getAverage(Number.MAX_VALUE - 2, Number.MAX_VALUE), Number.MAX_VALUE - 1);
assert.equal(tasks.getAverage(Number.MAX_VALUE, -Number.MAX_VALUE / 2), Number.MAX_VALUE / 4);

My code is the following (I took it from here):

function getAverage(value1, value2) {
  return parseInt(value1 / 2) + parseInt(value2 / 2) + (((value1 % 2) + (value2 % 2)) / 2);
}

But the value returned is somehow 16... If I use the basic (a+b)/2, then its Infinity. I need to get the numerical infinity value of 1.7976931348623157e+308. How is it possible?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source