WMLScript scale function library

Source: Internet
Author: User
This section will discuss the WMLScript library of scale. 6.1WMLScript rules these scale function libraries provide a mechanism to expand the WMLScript language. these specific function libraries must comply with the WMLScript rules. The WMLScript pattern under the supported data pattern should be

This section will discuss the WML Script library of scale.

  6.1 WML Script rules

These scale function libraries provide a mechanism to expand the WML Script language. these specific function libraries must comply with the WML Script rules.

Supported data landscape

The following WML Script pattern is applied to the definition of a program, which records the pattern of program parameters and rotary values.

Boolean

Integer

Float

String

Invalid

In addition, if both the integer and floating-point parameter values can be received, number can be used to record the parameter pattern. if the applied pattern is supported, any can be used to record the pattern.

Data structure conversion

The function library program produces errors in the same way as the WML Script language.

The invalid program parameter will generate the return value of invalid.

If the parameters of the program cannot be converted to the parameter pattern required, the return value of invalid is generated.

Errors related to the program result in returning an appropriate error code. The value depends on how each program is defined.

  6.2 Lang function library

Name: Lang

Clarification: The program contained in this function library is closely related to the core of the WML Script language.

Abs

Program: abs (value)

Clarify: returns the best value of the number given.

If the given number is an integer, the return value is an integer.

If the given number is a floating point number, the floating point number is returned.

Parameter: value = number.

Return value: number or invalid.

Exception status: var a =-3;

Var B = Lang. abs (a); // B = 3

Min

Model: var a =-3

Var B = Lang. abs ();

Var c = Lang. min (a. B );

Var d = Lang. min (45, 76.3); // d = 45 (ingteger)

Var e = Lang. min (45, 76.3); // e = 45 (ingteger)

Max

Program: max (value1, value2)

Clarification: The return value gives a greater margin between the two numbers. The return value is similar to the value of the selected value and the pattern in the pattern. the selection method is as follows:

The integer and floating-point number conversion rules of the WML Script operator data pattern can be used to confirm the data pattern, so as to perform the matching action.

Parameter: value1 = number

Value2 = number

Return value: number or invalid

Exception status: None

Model: var a =-3;

Var B = Lang. abs (a); // B = 3

Var c = Lang. min (a. B );

Var d = Lang. min (45, 76.3); // d = 45 (ingteger)

Var e = Lang. min (45, 76.3); // e = 45 (float)

ParseInt

Program: parseInt (value)

Clarification: return the integer defined by the string value. the valid integer syntax is defined by the WML Script value string syntax or the near value integer is a word. The following are additional parsing rules:

If the first character does not start with a,-, or decimal number, the interpretation ends.

Result: the parsed string returns an integer.

Model: var I = Lang. parseInt ('20140901'); // I = 1234

Var j = Lang. parseInt ('2017 m/s'); // j = 100

ParseFloat

Program: parseFloat (value)

Clarification: return the floating point value defined by the string value. the valid floating point number syntax is defined by the string syntax of the WML Script value or the real word of the near-value integer. The following are additional parsing rules:

The first character cannot be parsed into a floating-point expression, and the parsing ends.

End: convert the parsed string to a floating point.

Parameter: value = string

Return value: floating point number or invalid

Exception status: if a parsing error occurs, invalid is returned.

Model: var a = Lang. parseFloat ('192. 7Hz '); // a = 123

Var B = Lang. parseFloat ('7. 34e2Hz '); // B = 7.34e2

Var c = Lang. parseFloat ('70. 0e-2 f'); // c = 70.0e-2

Var d = Lang. parseFloat ('-1. c'); // d = 0.1

Var e = Lang. parseFloat ('20140901'); // e = 100

Var f = Lang. parseFloat ('number: 5.5 '); // f = invalid

Var g = Lang. parseFloat ('7. 3e meters '); // g = invalid

Var h = Lang. parseFloat ('7. 3e-m/s'); // h = invalid

IsInt

Program: isInt (value)

Clarification: if the pre-values can be converted into integers by parseInt (value), the return value is true. otherwise, false is returned.

Parameter: value = any value

Return value: Boolean or invalid

Exception status: None

Model: var a = Lang. inInt ('-123'); // ture

Var a = Lang. minInt ('192. 33'); // ture

Var a = Lang. minInt ('string'); // false

Var a = Lang. minInt ('#123'); // false

Var a = Lang. minInt ('invalid'); // invalid

IsFloat

Program: isFloat (value)

Clarification: if the pre-values can be converted into integers by parseInt (value), the return value is true. otherwise, false is returned.

Parameter: value = any value

Return value: Boolean or invalid

Exception status: None

Model: var a = Lang. inInt ('-123'); // ture

Var a = Lang. minInt ('192. 33'); // ture

Var a = Lang. minInt ('string'); // false

Var a = Lang. minInt ('#123'); // false

Var a = Lang. minInt ('invalid'); // invalid

MaxInt

Program: maxInt ()

Clarification: returns the largest integer.

Parameter: None

Return value: integer 2147483647

Exception status: None

Model: var a = Lang. minInt ();

MinInt

Program: minInt ()

Clarification: returns the smallest integer.

Parameter: None

Return value: Integer-2147483647

Exception status: None

Model: var a = Lang. minInt ();

Float

Program: float ()

Clarification: If floating point numbers are supported, true is returned. if not, false is returned.

Parameter: None

Return value: Boolean

Exception status: None

Model: var floatsSupported = Lang. float ();

Exit

Program: exit (value)

Clarification: terminate the interpretation of WML Script bit codes, return to the control of the interpreter that calls WML Script, and return the specified value. you can apply this program to fulfill the termination of the general program, in addition, the fulfillment of WML Script bit codes must end.

Parameter: valre = any value

Return value: None. this program stops interpreting

Exception status: None

Example: Lang. exit ('value: 'myval); // Returns a string

Lang, exit (invalid); // Returns invalid

Abort

Program: abort (errorDescription)

Clarify: interrupt the interpretation of WML Script bit codes, return to the control of the interpreter that calls WML Script, and return errorDescription. you can apply this program to perform abnormal interruptions, the caller detects a serious error. the fulfillment of WML scripts must be interrupted.

If the errorDescription pattern is invalid, the string invalid is used instead of the application of errorDescription.

Parameter: errorDescription = string

Return value: None. this program stops interpreting

Exception status: None

Example: Lang. abort ('Error: 'errval); // Error value string

Radndom

Program: random (value)

Clarification: return an integer that is greater than or equal to zero, but must be smaller than the given value. The return value is randomly selected from near normal distribution.

Parameter: value = integer

Return value: integer or invalid

Exception status: if the value is 0, the program returns 0

If the value is less than 0, the program returns invalid

Model: var a = 10;

Var B = Lang. random (5.1) * a; // B = 0 .. 50

Var c = Lang. random ('string'); // c = invalid

Reed

Program: seed (alue)

Clarification: Initialization requires random numbers and returning an empty string

If the value is 0 or a positive integer, the value is used for initialization. Otherwise, the random initialization value is applied.

If the value is a floating point number, Float.int () will be applied first to calculate the exact integer.

Parameter: value = integer

Return value: string or invalid]

Exception status: None

Model: var a = Lang. reed (123); // a =''

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.