[J3] SCALE(x,i) with complex x
Steven G. Kargl
kargl at uw.edu
Sun Nov 5 03:28:59 UTC 2023
SCALE(X,I) was added to the Fortran standard in ISO/IEC standard
1539:1991 (i.e., Fortran 90 for the youngster) where X is REAL
and I is INTEGER. The result of the function is X*2**I, and this
can be performed without any floating point rounding issues/errors.
Is there any reason that the restriction of X to REAL cannot be
changed to allow for a COMPLEX entity? The scale factor would
be applied to both the real and imaginary parts of the entity.
Compare
PROGRAM FOO
INTEGER, PARAMETER :: KND = KIND(1.D0)
COMPLEX(KND) A, B
A = CMPLX(7.654321D0,1.23456789D0,KND)
B = SCALE(A,2)
PRINT *, B
END PROGRAM FOO
versus
PROGRAM FOO
INTEGER, PARAMETER :: KND = KIND(1.D0)
COMPLEX(KND) A, B
A = CMPLX(7.654321D0,1.23456789D0,KND)
B = CMPLX(SCALE(A%RE,2), SCALE(A%IM,2), KND)
PRINT *, B
END PROGRAM FOO
or, a worse, but obvious implementation
PROGRAM FOO
COMPLEX A, B
A = (1,1)
B = 2.0_KND**2 * A ! Evaluated as B = cmplx(2._KND**2,0._KND,KND) * A (?)
PRINT *, B
END PROGRAM FOO
--
Steve
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3950 bytes
Desc: not available
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20231104/be4f6135/attachment.bin>
More information about the J3
mailing list