From: "Vipul Parekh" <[log in to unmask]>
Sent: Tuesday, June 13, 2017 8:13 AM
> Those who program using Fortran will be served greatly if, in a future
> revision of the standard, some facility is introduced that allows them
> to write code that deals with literal constants more expressively and
> easily which also improves readability and brings expressions closer
> to the principle and ethos of For(mula) Tran(slation).
> With literal constants treated as having defaults of the corresponding
> intrinsic types and with the default real being required to only have
> a decimal precision of 6 and an exponent range of 37, many coders run
> to errors or make mistakes with their use of literal constants or end
> up with verbose expressions that deviate considerably from
> "black-board abstractions" . As readers will know well, examples
> include:
> integer(kind=IP) :: n
> n = 8589934592 ! Can be an error depending on the processor even
> ! if the constant is within the range
> ! handled by integer(kind=IP)
Use
integer(kind=IP) :: n
n = 8589934592 _IP
> ..
> real(WP) :: r
> complex(WP) :: c
> ..
> r = 1.0/3.0 ! Can have different precision than expected by a coder
Use
r = 1/3.0_WP
> c = ( 0.55, 0.45 ) ! ditto
Use
c = ( 0.55_WP, 0.45_WP )
> ..
> character(kind=c_char) :: s
> s = "Hello World!" ! Missing c_char_ prefix
>etc.
> Given this, can the language introduce a new statement, say
> LITERALS_KINDS, which can be applied to a given scoping unit that
> specifies the kinds of literal constants in constant expressions used
> in that scope? The syntax and rules of LITERALS_KINDS statement can
> be similar to that of USE statement but with restrictions similar to
> ONLY specifier of needing to include a list and which covers only the
> intrinsic types in the language.
> So for example, if a coder can do:
> module m
..
> USE ..
> LITERAL_KINDS :: integer => integer(kind=xx), real => real(yy)
..
> IMPLICIT ..
..
> real(..), parameter :: PI = 4.0*atan(1.0) ! 4.0 and 1.0 literals
> treated as if 4.0_yy and 1.0_yy
It isn't necessary to write every integer constant as as a real:
real(..), parameter :: PI = 4 * atan(1.0_WP)
reads better.
> integer(kind=..) :: i
> real(kind=..) :: x
..
> i = 2147483648 ! literal treated as 2147483648_xx
Then why not just add the KIND, as in 2147483648_xx
> x = exp(3.0) ! literal treated as 3.0_yy
ditto.
> contains
..
> subroutine foo( .. )
..
> real(..) :: y
..
> y = 2.0*PI ! literal treated as 2.0_yy
y = 2 * PY
is cleaner.
..
> end subroutine foo
> subroutine bar( .. )
..
> LITERAL_KINDS :: integer => integer(kind=zz)
..
> integer(..) :: n
..
> n = 1000000 + n ! literal treated as 1000000_zz
..
> end subroutine bar
> end module m
This seems to be unnecessary clutter.
Being able to specify a KIND in one place makes it easy to
change the precision of variables, constants, and intrinsics
where the KIND can be specified.
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
|