Ada Programming Operators
Ada Programming Operators
All bookshelves > Computer science > Programming languages > Ada Programming
Contents
1 Operators
1.1 Standard operators
1.1.1 Logical operators
1.1.2 Relational operators
1.1.3 Binary adding operators
1.1.4 Unary adding operators
1.1.5 Multiplying operator
1.1.6 Highest precedence operator
1.2 Shortcut operators
1.3 Membership tests
1.4 See also
1.4.1 Wikibook Augusta Ada King, Countess
1.4.2 Ada 95 Reference Manual of Lovelace.
1.4.3 Ada 2005 Reference Manual
1.4.4 Ada Quality and Style Guide
2 Operators: &
2.1 As operator
2.1.1 Concatenating arrays
2.2 Common non-standard operations
2.2.1 Concatenating strings
2.3 See also
2.3.1 Wikibook
2.3.2 Ada 95 Reference Manual
2.3.3 Ada 2005 Reference Manual
3 Operators: **
3.1 Operator
3.1.1 Standard Operations
[Link] Arithmetic Power of
[Link].1 Usage
[Link].2 Working Example
3.2 See also
3.2.1 Wikibook
3.2.2 Ada 95 Reference Manual
3.2.3 Ada 2005 Reference Manual
4 Operators: *
4.1 Operator
4.1.1 Standard Operations
[Link] Arithmetic Multiplication
[Link].1 Usage
19.1 Operator
19.1.1 Standard Operations
[Link] Arithmetic Addition
[Link] Plus sign
[Link].1 Usage
19.1.2 Common Non-Standard Operations
[Link] Type Convertion
19.2 See also
19.2.1 Wikibook
19.2.2 Ada 95 Reference Manual
19.2.3 Ada 2005 Reference Manual
20 Operators: rem
20.1 Operator rem
20.2 See also
20.2.1 Wikibook
20.2.2 Ada 95 Reference Manual
20.2.3 Ada 2005 Reference Manual
20.2.4 Ada Quality and Style Guide
21 Operators: xor
21.1 Logical operator
21.1.1 Boolean operator
21.1.2 Boolean operator on arrays
21.1.3 Bitwise operator
21.2 See also
21.2.1 Wikibook
21.2.2 Ada 95 Reference Manual
21.2.3 Ada 2005 Reference Manual
21.2.4 Ada Quality and Style Guide
1 Operators
1.1 Standard operators
Ada allows operator overloading for all standard operators and so the following summaries
can only describe the suggested standard operations for each operator. It is quite possible to
misuse any standard operator to perform something unusual.
Each operator is either a keyword or a delimiter -- hence all operator pages are redirects to
the appropiate keyword or delimiter.
and
and , (also keyword and)
or
or , (also keyword or)
xor
exclusive or , (also keyword xor)
/=
Not Equal x≠y, (also special character /=)
=
+
Add x + y, (also special character +)
-
Subtract x - y, (also special character -)
&
Concatenate , x & y, (also special character &)
+
Plus sign + x, (also special character +)
-
Minus sign - x, (also special character -)
*
Multiply, x×y, (also special character *)
/
Divide x / y, (also special character /)
mod
modulus (also keyword mod)
rem
remainder (also keyword rem)
**
Power xy, (also special character **)
not
logical not , (also keyword not)
abs
absolute value | x | (also keyword abs)
and then
e.g. if Y /= 0 and then X/Y > Limit then ...
or else
e.g. if Ptr = null or else Ptr.I = 0 then ...
in
element of, , e.g. if I in Positive then, (also keyword in)
not in
not element of, , e.g. if I not in Positive then, (also keywords not in)
Ada Programming
Ada Operators
and and then > + abs &
or or else >= - mod
xor = < * rem in
not /= <= ** / not in
2 Operators: &
2.1 As operator
2.1.1 Concatenating arrays
Any array type (including fixed Strings) can be concatenated using the & operator. You can also
append a single element to an array.
Ada Programming/Delimiters
Ada Programming/Operators
3 Operators: **
3.1 Operator
3.1.1 Standard Operations
The "**" operator is defined as arithmetic power of for all numeric types.
[Link].1 Usage
with Ada.Text_IO;
procedure Operator_Power is
A : constant Float := 5.0 ** 2; -- A is now 25.0
B : constant Integer := 5 ** 2; -- B is also 25
begin
T_IO.Put ("A = ");
F_IO.Put (
Item => A,
Fore => 3,
Aft => 1,
Exp => 0);
T_IO.New_Line;
T_IO.Put ("B = ");
I_IO.Put (
Item => B,
Width => 3,
Base => 10);
T_IO.New_Line;
end Operator_Power;
Ada Programming
Ada Programming/Delimiters
Ada Programming/Operators
([Link] )
4 Operators: *
4.1 Operator
4.1.1 Standard Operations
The "*" operator is defined as arithmetic multiplication for all numeric types.
[Link].1 Usage
with Ada.Text_IO;
procedure Operator_Multiply is
A : constant Float := 5.0 * 2.0; -- A is now 10.0
B : constant Integer := 5 * 2; -- B is also 10
begin
T_IO.Put ("A = ");
F_IO.Put (
Item => A,
Fore => 3,
Aft => 1,
Exp => 0);
T_IO.New_Line;
T_IO.Put ("B = ");
I_IO.Put (
Item => B,
Width => 3,
Base => 10);
T_IO.New_Line;
end Operator_Multiply;
In addition to standard Strings this operator is also defined for Bounded_String and
Unbounded_String.
[Link].1 Usage
The character replication operator is part of the [Link] package. You need to
with and use the package to make the operator visible.
with Ada.Text_IO;
with [Link];
procedure Operator_Multiply_2 is
use [Link];
begin
T_IO.Put_Line ("A = " & A);
end Operator_Multiply_2;
In addition to standard fixed strings this operator is also defined for Bounded_String and
Unbounded_String.
[Link].1 Usage
The string replication operator is part of the [Link] package. You need to with
and use the package to make the operator visible.
with Ada.Text_IO;
with [Link];
procedure Operator_Multiply_3 is
use [Link];
begin
T_IO.Put_Line ("A = " & A);
end Operator_Multiply_3;
Ada Programming
Ada Programming/Delimiters
Ada Programming/Operators
([Link] )
A.4.5 Unbounded-Length String Handling
([Link] (Annotated
([Link] )
5 Operators: -
5.1 Operator
5.1.1 Standard Operations
The "-" operator is defined as arithmetic subtraction for all numeric types.
[Link].1 Usage
The "-" unary operator is defined as arithmetic negative sign for all numeric types.
[Link].1 Usage
Ada Programming
Ada Programming/Delimiters
Ada Programming/Operators
Ada Programming/Mathematical calculations
([Link] )
4.5.4 Unary Adding Operators
([Link] (Annotated
([Link] )
6 Operators: /=
6.1 Operator
The operator /= compares two values on inequality. It is predefined for all non limited types.
The operator will also be defined if a suitable operator = is available.
Note that in Ada the representation for this operator was chosen for resembling the
mathematical symbol ≠, in the same way than <= resembles , or >= resembles .
Ada Programming
Ada Programming/Delimiters
7 Operators: /
7.1 Operator
7.1.1 Standard operations
The "/" operator is defined as arithmetic division for all numeric types.
[Link].1 Usage
Ada Programming
Ada Programming/Delimiters
Ada Programming/Operators
Ada Programming/Mathematical calculations
8 Operators: =
8.1 Operator
The operator = compares two values on equality. It is predefined for all non limited types.
Ada Programming
Ada Programming/Delimiters
([Link] )
9 Operators: abs
This keyword is used for the operator that gets the absolute value of an integer number.
y := abs (x);
Ada Programming
Ada Programming/Keywords
10 Operators: and
10.1 Logical operator
10.1.1 Boolean operator
Shortcut operators are used to make the evaluation of parts of boolean expressions
conditional: and then, or else. This should never be done to speed up the evaluation (with
modern optimizing compilers, it will possibly not have that effect). The correct use is to
prevent the evaluation of expressions known to raise an exception.
In the example above, G (Dog) is only called when the pointer Dog is not null, i.e. it actually
points to something.
Actually and then and or else are not operators in the sense of the reference manual, they
are called 'Short-circuit Control Forms'. The difference is that (true) operators can be
redefined (i.e. overloaded), whereas these cannot. They are however defined for any boolean
type.
Since Ada allows parallel evaluation of the arguments for an expression, shortcut operators
are not the standard way of evaluating boolean expressions. In case the final result of the
evaluation is guaranteed to be the same, the compiler is allowed to use a shortcut
evaluation.
The and operator is applied to each pair of boolean elements from the left and right arrays.
The result has the same bounds than the left operand.
X : Month_Array := Function_1;
Y : Month_Array := Function_2;
Z : Month_Array := X and Y;
The operator and could be used with modular types to perform bitwise operations.
Ada Programming
Ada Programming/Keywords
Ada Programming/Operators
Ada Programming/Keywords/interface
11 Operators: >=
11.1 Operator
The operator >= compares two values on greater than or equal to. It is predefined for all
discrete types.
Ada Programming
Ada Programming/Delimiters
12 Operators: >
12.1 Operator
The operator > compares two values on being greater. It is predefined for all discrete types.
Ada Programming
Ada Programming/Delimiters
13 Operators: in
This keyword is used in:
Ada Programming
Ada Programming/Keywords
14 Operators: <=
14.1 Operator
The operator <= compares two values on less than or equal to. It is predefined for all
discreed types.
Ada Programming
Ada Programming/Delimiters
15 Operators: <
15.1 Operator
The operator < compares two values on less than. It is predefined for all discrete types.
Ada Programming
Ada Programming/Delimiters
16 Operators: mod
This keyword is used in the mod operator and in the declaration of modular types.
Ada Programming
Ada Programming/Keywords
17 Operators: not
This keyword is used in:
Ada Programming
Ada Programming/Keywords
([Link] )
4.5.6 Highest Precedence Operators
([Link] (Annotated
([Link] )
Annex P (informative) Syntax Summary
([Link] (Annotated
([Link] )
18 Operators: or
18.1 Logical operator
18.1.1 Boolean operator
In the below example the function G is only called when F(X) returns the value False.
Walk_The_Dog;
end if;
This shortcut operator is sometimes used to speed up the evaluation of boolean expressions,
but the Ada Style Guide recommends to compare the performance of both forms before
switching one to the other. In general, it is good idea to use or else in sake of performance
only when the second expression involves a function call.
The or else form is also used when the second expression is known to raise an exception
unless the first expression is False.
Unlike C/C++, Ada short-cut operators are not the standard way to evaluate boolean
expressions. This is because Ada is designed to do by default what is generally safer, but lets
the programmer request a different behaviour.
The or operator is applied to each pair of boolean elements from the left and right arrays.
The result has the same bounds than the left operand.
X : Month_Array := Function_1;
Y : Month_Array := Function_2;
Z : Month_Array := X or Y;
The operator or could be used with modular types to perform bitwise operations.
18.2.2 delay
Ada Programming
Ada Programming/Keywords
Ada Programming/Operators
([Link]
19 Operators: +
19.1 Operator
19.1.1 Standard Operations
The "+" operator is defined as arithmetic addition for all numeric types.
The "+" operator is defined as arithmetic plus sign for all numeric types.
[Link].1 Usage
The operator plus sign is often used to create a type conversion operator:
Ada Programming
Ada Programming/Delimiters
Ada Programming/Operators
Ada Programming/Mathematical calculations
20 Operators: rem
20.1 Operator rem
The rem keyword is used as the remainder operator, that is, the remainder of the signed
integer division. The following formula applies:
A = (A / B) * B + (A rem B)
Ada Programming
Ada Programming/Keywords
21 Operators: xor
21.1 Logical operator
21.1.1 Boolean operator
X : Month_Array := Function_1;
Y : Month_Array := Function_2;
Z : Month_Array := X xor Y;
The operator xor could be used with modular types and also with boolean arrays to perform
bitwise operations.
Ada Programming
Ada Programming/Keywords
Ada Programming/Operators
([Link] )
4.5.1 Logical Operators and Short-circuit Control Forms
([Link] (Annotated
([Link] )
Annex P (informative) Syntax Summary
([Link] (Annotated
([Link] )
Von „[Link]
Kategorien: Books with print version | Ada Programming/Ada 2005 feature | Ada
Programming | Ada programming language | Programming
Diese Seite wurde zuletzt am 30. Juni 2006 um 23:35 Uhr geändert.
All text is available under the terms of the GNU Free Documentation License (see Copyrights for
details).
Wikibooks® is a registered trademark of the Wikimedia Foundation, Inc.
Datenschutz
Über Wikibooks
Impressum