I have been trying to understand the use of the intrinsic TRANSFER, to store a mixture of integer and real values in an integer array and then recover them. I had hoped to do this in a more standard conforming way.
Anyway, I experimented with TINY to see how real zero might look. I wrote the following program to test real underflow and how this might be stored.
integer*4, parameter :: sp = selected_real_kind (p=6) real(sp) :: x integer*4 i(4),j ! i = 0 write (*,*) 'test for real kind =',sp, kind(1.0), kind(1.0d0) x = 1 i(1) = transfer (x,j) write (*,*) '1 ', x, i ! x = tiny(x) i(1:2) = transfer (x,j,2) write (*,*) 'tiny', x, i ! x = x/2 i(1:2) = transfer (x,j,2) write (*,*) 'x/2 ', x, i ! end
this produced the following result:
Intel(R) Visual Fortran Compiler XE for applications running on IA-32, Version 126.96.36.1994 Build 20120612
Copyright (C) 1985-2012 Intel Corporation. All rights reserved.
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.
test for real kind = 4 4 8
1 1.000000 1065353216 0 0 0
tiny 1.1754944E-38 8388608 0 0 0
x/2 5.8774718E-39 4194304 0 0 0
To my surprise x/2 is not zero !
My aim is to transfer 4 byte and 8 byte reals into an integer*4 vector for later recovery, but I thought I'd test a 4 byte real first. I find the use of the size argument of TRANSFER a bit confusing.