Compute average of two numbers without overflow | Javascript code to compute average of two numbers ; Function to compute average of two numbers ; Assigning maximum integer value ; Average of two equal numbers is the same number ; Function to get the average of 2 numbers
const INT_MAX = 2147483647 ; function compute_average ( a , b ) { return Math . floor ( ( a + b ) / 2 ) ; } let a = INT_MAX ; let b = - INT_MAX - 1 ; document . write ( " " + INT_MAX + " " ) ; document . write ( " " + compute_average ( a , b ) + " " ) ;