함수(JavaScript)
var epsilon = 0.00000000001; // Some very small number to test against. // The test function for integers. function integerCheck(a, b, c) { // The test itself. if ( (a*a) == ((b*b) + (c*c)) ) return true; return false; } // End of the integer checking function. // The test function for floating-point numbers. function floatCheck(a, b, c) { // Make the test number. var delta = ((a*a) - ((b*b) + (c*c))) // The test requires the absolute value delta = Math.abs(delta); // If the difference is less than epsilon, then it's pretty close. if (delta < epsilon) return true; return false; } // End of the floating-poing check function. // The triplet checker. function checkTriplet(a, b, c) { // Create a temporary variable for swapping values var d = 0; // First, move the longest side to position "a". // Swap a and b if necessary if (b > a) { d = a; a = b; b = d; } // Swap a and c if necessary if (c > a) { d = a; a = c; c = d; } // Test all 3 values. Are they integers? if (((a % 1) == 0) && ((b % 1) == 0) && ((c % 1) == 0)) { // If so, use the precise check. return integerCheck(a, b, c); } else { // If not, get as close as is reasonably possible. return floatCheck(a, b, c); } } // End of the triplet check function. // The next three statements assign sample values for testing purposes. var sideA = 5; var sideB = 5; var sideC = Math.sqrt(50.001); // Call the function. After the call, 'result' contains the result. var result = checkTriplet(sideA, sideB, sideC);
from MSDN : https://msdn.microsoft.com/ko-kr/library/yh6c50h7(v=vs.94).aspx
///848.
'지속가능티끌 > JavaScript' 카테고리의 다른 글
JavaScript. Object. Array (0) | 2016.07.28 |
---|---|
JavaScript. 개체 만들기. (0) | 2016.07.27 |
JavaScript. 연산자, 우선순위. Operators. (0) | 2016.07.27 |
JavaScript. 변수 (Variable). 전역,지역 (0) | 2016.07.27 |
JavaScript. 프로그램 흐름제어. if,while, for, break, continue. (0) | 2016.07.27 |
댓글