0% found this document useful (0 votes)
17 views

Elementary Types: Access Types Scalar Types

Elementary Types in Ada include scalar types like integers, characters, floating point numbers, and booleans. Integer types can be signed or unsigned modular types that wrap around. Character types include predefined 8-bit and 16-bit types as well as user-defined types. Enumeration types define an ordered sequence of enumeration literals. Floating point types specify precision in decimal digits. Fixed point types represent real numbers with a specified delta or distance between values.

Uploaded by

Zandra Eclipse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Elementary Types: Access Types Scalar Types

Elementary Types in Ada include scalar types like integers, characters, floating point numbers, and booleans. Integer types can be signed or unsigned modular types that wrap around. Character types include predefined 8-bit and 16-bit types as well as user-defined types. Enumeration types define an ordered sequence of enumeration literals. Floating point types specify precision in decimal digits. Fixed point types represent real numbers with a specified delta or distance between values.

Uploaded by

Zandra Eclipse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 9

Elementary Types

• Access Types
• Scalar Types
– Discrete Types
– Real Types
– Fixed Point Types
Discrete Types
• Integer Types
– Signed
type Marks is range 0..100;
finalScore : Marks;

FINALSCORE, midScore : Marks;


Unsigned (Modular) Types
• Modular types have wrap around:

type M is mod 7; -- values are 0,1,2,3,4,5,6


q : m := 6; -- initialization
q := q + 2; -- result is 1
Character Types
• Built in types
– Character (8-bit Latin-1)
– Wide_Character (16-bit Unicode/ISO 10646)
• Good enough for most purposes, but you
can define your own types:

type My_CharacterSet is (‘A’, ‘B’, ‘C’, ….);


Enumeration Types

• An enumeration type is a sequence of


ordered enumeration literals:

type Colors is (Red, Orange, Yellow, Green, Blue,


Indigo, Violet);
type State is (Off, Powering_Up, On);

NotYou
Youallowed
can
cannotin have
C arithmetic
add/subtract (increment or decrement)
operations on the value
of an enumeration
type BasicColors
enumeration type
types using the
is (Red, ‘Pred’ and
Orange, ‘Succ’
Yellow, Green,
keywords
Blue,
State’Pred
S1, (S1)
S2 : State;
Indigo, Violet);
typeState’Succ
S1
MyColors is(S2)
:= S1 + S2; -- Illegal
(Red, Orange, Yellow);
Boolean Types
• Predefined enumeration type
type Boolean is (False, True);

• Expressions of type boolean used in


– if statements
– while loops
– exit statements
Floating Point Types
type Double is digits 15;
– Creates a floating point type with 15 decimal
digits of precision

type Sin_Values is digits 10 range -1.0..1.0;

– Defines a type with 10 decimal digits of


precision and a valid range of values from -1.0
through 1.0
Ordinary Fixed Point Types

• The distance between values is implemented as a


power of 2
type Batting_Averages is delta 0.001 range
0.0..1.0;

– Batting_Averages is a fixed point type whose values are


evenly spaced real numbers in the range from 0 through
1. The distance between the values is no more than
1/1000. The actual distance between values may be
1/1024, which is 2-10
Decimal Fixed Point Types
• The distance between values is implemented as a power
of 10
type Balances is delta 0.01 digits 9 range
0.0 .. 9_999_999.99;
This important
The example also difference
showsinhow theAda
definition
allowsofyou
a to
decimalnumeric
specify fixed point
literals
typewith
fromunderscores
an ordinary fixed
point type isgroups
separating the specification
of digits. The
of the
underscore
number of is
digits to
used of improve
precisionreadability

You might also like