SCALE(3) - [MODEL:COMPONENTS] Scale a real value by a whole power of the radix
result = scale(x, i)
elemental real(kind=KIND) function scale(x, i)real(kind=KIND),intent(in) :: x integer(kind=**),intent(in) :: i
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
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
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
The return value is X * RADIX(X)**I, assuming that value can be represented by a value of the type and kind of X.
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_scaleResults:
> 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)
Fortran 95
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 intrinsic descriptions (license: MIT) @urbanjost
Nemo Release 3.1 | scale (3fortran) | November 02, 2024 |