J3/04-263
J3/04-263
Date 2004-02-29
To: J3
From: Michael Ingrassia
Subject: Unsigned Integers
The following rules are implemented in shipping compilers.
I propose Unsigned Integers be added to standard Fortran.
o UNSIGNED is an integer type
o an unsigned integer constant is a digit-string followed by the letter U
or the letter u , optionally followed by an underscore followed by
a kind parameter; the kind parameters shall match the integer
kind parameters
o arithmetic expressions shall not have both signed and unsigned integer
operands unless
1) the signed operand has value 0 ; the result type is the unsigned
integer type
2) the operation is intrinsic exponentiation; the result type
is the type of the left operand
o relational expressions shall deliver a result which depends on the
unaltered values of the operands
For example:
Consider a processor in which the kind numbers represent
the number of bytes.
-1_4 .LT. 17U_8 has the value .TRUE.
since -1 is less than 17. -1_4 is not widened to -1_8
and then interpreted as a very large unsigned number.
o the CASE construct shall admit unsigned integer expressions as case-exprs
o (formatted I/O)
unsigned integers may be read and written using I, B, O, and Z edit
descriptors
o (namelist I/O)
unsigned integers may be read and written. The written form of
an unsigned integer is the same as the form used for a positive
unsigned integer.
o (list-directed I/O)
unsigned integers may be read and written. Same written form as
for namelist I/O.
o (unformatted I/O)
unsigned integers may be read and written.
o Intrinsics
A new intrinsic function UNSIGNED(A [, KIND]) shall be added,
analogous to INT, but shall produce a result of unsigned type
instead of integer type.
A new intrinsic function SELECTED_UNSIGNED_KIND shall be added.
Where reasonable, operands which accept an argument of signed
integer type shall accept an argument of unsigned integer type
in its place. But ABS and SIGN shall not accept an argument of
unsigned integer type.
The MAX and MIN intrinsics shall not allow operands of both
signed and unsigned integer type.
o Assignment shall be value-preserving where possible.
For example: Consider a processor in which kind numbers
represent the number of bytes.
The assignment
UNSIGNED(8) U
SIGNED(4) I
I = 17_4
U = I
gives U the same value represented by literal 17U_8.
The assignment
UNSIGNED(1) U
SIGNED(4) I
U = 255U_1
I = U
gives I the same value represented by literal 255_8.