You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					19 lines
				
				684 B
			
		
		
			
		
	
	
					19 lines
				
				684 B
			| 
											3 years ago
										 | // https://rwaldron.github.io/proposal-math-extensions/
 | ||
|  | module.exports = Math.scale || function scale(x, inLow, inHigh, outLow, outHigh) { | ||
|  |   if ( | ||
|  |     arguments.length === 0 | ||
|  |       // eslint-disable-next-line no-self-compare
 | ||
|  |       || x != x | ||
|  |       // eslint-disable-next-line no-self-compare
 | ||
|  |       || inLow != inLow | ||
|  |       // eslint-disable-next-line no-self-compare
 | ||
|  |       || inHigh != inHigh | ||
|  |       // eslint-disable-next-line no-self-compare
 | ||
|  |       || outLow != outLow | ||
|  |       // eslint-disable-next-line no-self-compare
 | ||
|  |       || outHigh != outHigh | ||
|  |   ) return NaN; | ||
|  |   if (x === Infinity || x === -Infinity) return x; | ||
|  |   return (x - inLow) * (outHigh - outLow) / (inHigh - inLow) + outLow; | ||
|  | }; |