Check whether the language has different data types by using JScript.

Source: Internet
Author: User

1. templates can be used for data types, such as C ++, which is relatively simple, but C is difficult.

2. If there is no data type, it is necessary to judge all points for execution. Time is complex and time is not optimized, and the code is easy to understand. For example, test the right triangle.

VaR Epsilon = 0.00000000001; // small numbers to be tested. </P> <p> // test the integer function. <Br/> function integercheck (a, B, c) <br/>{< br/> // test. <Br/> If (A * A) = (B * B) + (C * C) <br/> return true; </P> <p> return false; <br/>}// The End Of The integer check function. </P> <p> // test the floating point function. <Br/> function floatcheck (a, B, c) <br/>{< br/> // obtain the test value. <Br/> var Delta = (A * A)-(B * B) + (C * C ))) </P> <p> // absolute value required for testing <br/> Delta = math. ABS (DELTA); </P> <p> // if the difference is smaller than Epsilon, it is quite close. <Br/> If (delta <epsilon) <br/> return true; </P> <p> return false; <br/>}// the end of the floating point check function. </P> <p> // ternary check. <Br/> function checktriplet (a, B, c) <br/>{< br/> // create a temporary variable for exchanging values <br/> var D = 0; </P> <p> // first move the longest value to the location "". </P> <p> // if necessary, exchange a and B <br/> If (B> A) <br/>{< br/> d =; <br/> A = B; <br/> B = D; <br/>}</P> <p> // if necessary, exchange A and C <br/> If (C>) <br/>{< br/> d = A; <br/> A = C; <br/> C = D; <br/>}</P> <p> // test all three values to see if they are integers? <Br/> If (a % 1) = 0) & (B % 1) = 0) & (C % 1) = 0) <br/>{< br/> // If yes, use the exact check. <Br/> return integercheck (A, B, C); <br/>}< br/> else <br/>{< br/> // if not, take as close as possible. <Br/> return floatcheck (A, B, C); <br/>}< br/>}// END OF THE TERNARY check function.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.