Skip to main content
Engineering LibreTexts

4.6: Declarations, Extended Size Variables

  • Page ID
    54253
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    The size or range of a number that can be held in a Fortran variable is limited. Special declarations can be used to provide variables with extended or larger ranges. Only integer and real variables are addressed here.

    Integers

    As previously noted, the range of an integer value can range between −2,147,483,648 and +2,147,483,647. In the unlikely event that a larger range is required, a special declaration can be used to extend the range. The kind specifier is used with the integer declaration.

    For example, to declare a variable bignum with an extended range, the integer declaration would be as follows:

    integer*8 :: bignum
    

    or

    integer(kind=8) :: bignum
    

    Both of these equivalent declarations use more space for the variables (8 bytes instead of the normal 4) in order to provide a larger range. The extended range of integer variables declared with the *8 or kind=8 is –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

    Real

    As previously noted, the range is approximately \(\pm1.7 \times 10^{\pm 38}\) supporting about 7 digits of precision. If more precision is required, the kind specifier can be used.

    For example, to declare a real variable rnum with an extended range, the declaration would be as follows:

    real*8 :: rnum
    

    or

    real(kind=8) :: rnum
    

    Both of these equivalent declarations use more space for the variables (8 bytes instead of the normal 4) in order to provide a larger range. The extended precision of real variables declared with the *8 or kind=8 is approximately \(−2.2 \times 10^{−308}\) to \(+1.8 \times 10^{+308}\) which supports a much larger range with about 15 digits of precision.


    This page titled 4.6: Declarations, Extended Size Variables is shared under a CC BY-NC-SA 3.0 license and was authored, remixed, and/or curated by Ed Jorgensen via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?