Manual Reference Pages  - scale (3fortran)

NAME

SCALE(3) - [MODEL_COMPONENTS] Scale a real value by a whole power of the radix

SYNOPSIS

result = scale(x, i)

         elemental real(kind=KIND) function scale(x, i)

real(kind=KIND),intent(in) :: x integer(kind=**),intent(in) :: i

CHARACTERISTICS

o X is type real of any kind
o I is type an integer of any kind
o the result is real of the same kind as X

DESCRIPTION

SCALE(3) returns x * RADIX(X)**I.

It is almost certain the radix(base) of the platform is two, therefore SCALE(3) is generally the same as X*2**I

OPTIONS

o X : the value to multiply by RADIX(X)**I. Its type and kind is used to determine the radix for values with its characteristics and determines the characteristics of the result, so care must be taken the returned value is within the range of the characteristics of X.
o I : The power to raise the radix of the machine to

RESULT

The return value is X * RADIX(X)**I, assuming that value can be represented by a value of the type and kind of X.

EXAMPLES

Sample program:

    program demo_scale
    implicit none
    real :: x
    complex :: c
    integer :: i
       x = 1.0
       print *, (scale(x,i),i=1,5)
       x = 3.0
       print *, (scale(x,i),i=1,5)
       print *, (scale(log(1.0),i),i=1,5)
       ! on modern machines radix(x) is almost certainly 2
       x = 178.1387e-4
       i = 5
       print *, x, i, scale(x, i), x*radix(x)**i
       ! x*radix(x)**i is the same except roundoff errors are not restricted
       i = 2
       print *, x, i, scale(x, i), x*radix(x)**i
       ! relatively easy to do complex values as well
       c=(3.0,4.0)
       print *, c, i, scale_complex(c, i)!, c*radix(c)**i
    contains
    function scale_complex(x, n)
    ! example supporting complex value for default kinds
    complex, intent(in) :: x
    integer, intent(in) :: n
    complex :: scale_complex
       scale_complex=cmplx(scale(x%re, n), scale(x%im, n), kind=kind(x%im))
    end function scale_complex
    end program demo_scale

Results:

     > 2.00000000 4.00000000  8.00000000     16.0000000 32.0000000
     > 6.00000000 12.0000000 24.0000000      48.0000000 96.0000000
     > 0.00000000 0.00000000  0.00000000     0.00000000 0.00000000
     > 1.78138707E-02    5   0.570043862      0.570043862
     > 1.78138707E-02    2   7.12554827E-02   7.12554827E-02
     > (3.00000000,4.00000000) 2 (12.0000000,16.0000000)

STANDARD

Fortran 95

SEE ALSO

DIGITS(3), EPSILON(3), EXPONENT(3), FRACTION(3), HUGE(3), MAXEXPONENT(3), MINEXPONENT(3), NEAREST(3), PRECISION(3), RADIX(3), RANGE(3), RRSPACING(3), SET_EXPONENT(3), SPACING(3), TINY(3)

fortran-lang intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 scale (3fortran) April 28, 2024
Generated by manServer 1.08 from cbd90ff2-89c5-4e94-8c6e-3cc68f5b86fa using man macros.