TEIMSI
Developer's platform of programming text codes
Home|Utilities|Forum|Documentation

Table of contents -> Chapter 7 - Functions and operators Reference


The default operators and functions are key elements in programming with TEIMSI as well as in any language, between operators are the Numerical and logical. Operators work with two operands only. The Numerical operands work with numbers and the logical with booleans, nevertheless they can be shared with each other, lets see some trivial examples.


	// These examples show the multiplication operator "*":

		alert(100*5)				// Shows "500"
		alert(true*false)			// Shows "0"
		alert(true*false==false)		// Shows "true"

	
	// These examples show the and logical operator "&&":

		alert( true && false )		// Shows "false"
		alert( 100 && 0.0 )			// Shows "false"
		alert( 100 && 0.00000001 )		// Shows "true" because neither operand is "false" or "zero".

	// When combined with numbers boolean, true is 1 and false is 0, resulting numbers:

		alert( true * 11 )			// Shows "11"
		alert( false * 11 )			// Shows "0"


Operator precedence determines how an equation or expression that uses operators and/or functions is evaluated, for example 88 * 32 + 43 is evaluated as (88 * 32) +43 rather than 88 * (32 + 43); the operator "+" (plus) has lower precedence than "*" (multiplication).

When using logical operator the operands "booleans". Operators always use two operands. Below the logical and numerical operators are described, the list also shows the order of precedence for operators (those with lower precedence are above).

OperatorNameCategoryDescriptionType of returned value
 
 
    &&ANDLogicalReturns "true" only if both operands are "true".Boolean
    ||ORLogicalReturns "true" if some operand is "true".Boolean
    ===SameNumerical/LogicalReturns "true" if the operands are the same.Boolean
    !==Not SameNumerical/LogicalReturns "true" if the operands are not the same.Boolean
    ==EqualNumerical/LogicalReturns "true" if the operands are equal.Boolean
    !=Not equalNumerical/LogicalReturns "true" if the operands are not equal.Boolean
    <=Less or equalNumericalReturns "true" if the first operand is less or equal.Boolean
    >=Greater or equalNumericalReturns "true" if the first operand is greater or equal.Boolean
 
    <<Shift to the leftNumerical for integersCalculates "operand1 * (2 ** operand2)".Integer number of 32 bits
    >>Shift to the rightNumerical for integersCalculates the floor of "operand1 / (2 ** operand2)".Integer number of 32 bits
    <LessNumericalReturns "true" if the first operand is less.Boolean
    >GreaterNumericalReturns "true" if the first operand is greater.Boolean
    +AdditionNumerical/TextAdds or concatenates the operands. (operand1 + operand2)String/Number
    -SubstractionNumericalCalculates (operand1 - operand2)Number
    /DivisionNumericalCalculates (operand1 / operand2)Number
    :RadiusNumericalCalculates sqrt(operand1**2 + operand2**2)Number
    **PotencyNumericalCalculates (operand1) powered to (operand2)Number
    *MultiplicationNumericalCalculates (operand1 * operand2)Number
    ^XORNumerical for integersCalculates (operand1 Xor operand2)Integer number of 32 bits
    &ANDNumerical for integersCalculates (operand1 And operand2)Integer number of 32 bits
    |ORNumerical for integersCalculates (operand1 Or operand2)Integer number of 32 bits
    %Rest of divisionNumericalCalculates (operand1 - operand2*floor(operand1/operand2))
 


Examples:


	alert(2**32)		// Shows 2 powered to 32

	alert(321 % 11)	// Displays "2", the remainder of dividing 321 by 11.  Because 2 = (321 - 11 * 29) =(321 - 11 * floor(321/11))

	alert(3 : 4)		// Shows "5", 5=sqrt(3*3+4*4)

	var num1=42.2
	var num2=30.1

	alert("num1 > num2 : " + (num1>num2))	// Shows "true"


It's possible to work in TEIMSI with all these operators (and even more if manually incorporated), but for an specific reason (with expressions it was needed to first process the greatest length operators) in the current TEIMSI version (0.95) it's recommended the use of parentheses with expressions that use both logical and numerical combined or with the use of the potency operator, for example the following expressions are evaluated as identical: "83*2**3" to "(83*2)**3", also is identical "43>12>>3" to "(43>12)>>3"; to avoid the inconvenience it should be expressed firstly as "83*(2**3)" and the previous expression as "43>(12>>3)", this problem can be explained by looking at the operators precedence table.

You can modify the precedence of operators editing the "protodb.dat" file in the "engine\internal" folder inside the TEIMSI editor folder (but must take care that the multiplication must be after the potency operator, and, "greater"/"lower" operators after the "shift" operators since they have the same character, otherwise would be generated unexpected syntax errors during compilation process of expressions).


Functions in TEIMSI.

The default functions are distinguished from the user functions. In the "protodb.dat" file described above, there are also prototypes of the TEIMSI default functions, the important thing there is the amount of parameters received by each one.

Since TEIMSI works with "variant" data type variables, is not necessary to specify what type of data is being used: for example a variable can change from a number data type to an array data type and reciprocally at any time. This mode is used in the "Jscript" language and in "P.H.P".

By using a function the number of parameters to use should be respected, in TEIMSI v0.95 is not possible for it to be arbitrary. For example to show the position of the letter "w" in the word "the whiskey" does not work::

alert(strpos("the whiskey","w"))

- But rather:

alert(strpos("the whiskey","w",0)) // Shows "4" which is the offset to reach the character.

- For the "strpos" function must receive three parameters.


To declare functions is very simple, this is an example of a program:

		task()
		alert(calculation(44,33))
	
		function task(){	alert("Hello, this will show how much is 44 * 33")	}
	
		function calculation(par1,par2){
			return par1*par2
		}


In the next chapter called "Functions for string type variables" we'll see the description of the default TEIMSI functions, and it's recommended to have read the topic CPU registers elements.

Many non default functions but with great utility can be found in The default Teimsi's Framework and the sample projects.



Go to top