Numeric Data Types

Integers: The most primitive numeric data type is integer.

Specification of Integer Data Type:

C has four different integers specification

int, short, long and char

but maximal and minimal values depends upon the what bit architecture of hardware is basically and in some languages these values represented as defined constants.

Like in Pascal: Maxint

Types of operations on Integers:

1) Arithmetic operation:
It is of basically of two types:

A) Binary operation: BinOp: integer * integer-> integer

Example addition (+), substraction (-) , multiplication(*), division(/), reminder(mod)

B) Unary Pperation: UnaryOp: integer-> integer
Negative(-), or identify(+), abs value

2) Relational Operations:
Signature is
Relop: Integer * integer-> Boolean
Where Relop maybe equal, not equal, less than, greater than,less-than-or-equal, greater-than-or-equal Relational operation compare the value of a two arguments data value and return Boolean (true or false value) data object as its result.

3) Assignment Operations: Signature
assignment: Integer* integer-> integer
assignment: Integer* integer -> integer

4) Bit operations:
In C, integers also plays the role of boolean values . Therefore additional bit operations are also defined.
Signature: BinOp: Integer*integer-> integer
Operator (&) for and the bits together
Operator(|) for or the bits together
Operator(<<) for shift the bit among others.

Implementation of integer

Most often using the hardware-defined integer storage representation and a set of hardware arithmetic and relational operations on integers.


Numeric Data Types : Sub Ranges of an Integer

Specification of Integer Data Types:

A sub-range of an integer data type is a subtype of the integer data type and consists of a sequence of integer values within some restricted range.


Declaration in Pascal


Declaration in Ada

A: integer range 1...10

Implementation: Its implementation basically has two advantages

1) smaller storage requirement :As a smaller range of values, a sub-range value can usually be stored in fewer bits than a general integer value.

2) Better type checking: More precise type checking to be performed on the value assigned to that variables.
Example if variable month is: Month: 1....12 then the assignment
Month:0 is invalid and can be detected at compile time.
If we use assignment Month: Month + 1
At runtime compiler check for range limit that should not be exceeded.

Facebook Likes