Home > Archive > Fortran > June 2004 > Re: Specifying at 16-bit integer
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: Specifying at 16-bit integer
|
|
| Clive Page 2004-06-25, 7:43 pm |
| In message <o_bAc.55815$0y.22968@attbi_s03>, James Van Buskirk
>module mykinds
> implicit none
> integer, parameter :: ik2 = selected_int_kind(4)
> integer, parameter :: test2a = abs(16-bit_size(1_ik2))
> integer, parameter :: test2b = max(kind(1.0),kind(1.0d0))*(1-2*test2a)
> real(test2b) :: test2c ! Fails if bit_size(1_ik2) /= 16
>! private test2a, test2b, test2c
>end module mykinds
Thanks very much, James, that appears to do the job in a pretty
fool-proof manner. I must now test it out on a selection of compilers,
but I rather think that none of them now fails the 16-bit test.
Thanks also to Arjen and Richard for their comments, the latter also for
pointing out that the C compatibility features ought to provide a
simpler solution "real soon now".
--
Clive Page
| |
| Richard Maine 2004-06-25, 7:43 pm |
| Clive Page <junk@page.demon.co.uk> writes:
> In message <o_bAc.55815$0y.22968@attbi_s03>, James Van Buskirk
>
> Thanks very much, James, that appears to do the job in a pretty
> fool-proof manner.
I was thinking of James when I said "(might be a way, but if so, it
would take some thought)". I almost mentioned his name as someone
likely to have either done it or be able to off the top of his head,
but I didn't want to put him on the spot. Looks like I need not
have worried about that. :-)
--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
| |
| James Van Buskirk 2004-06-25, 7:43 pm |
| "Richard Maine" <nospam@see.signature> wrote in message
news:m1y8mmj9zr.fsf@macfortran.local...
> Looks like I need not
> have worried about that. :-)
But I worry a lot sometimes. As I was walking to RMCF it
occurred to me that I might have problems if the arithmetic
overflowed. Mind you, that would require rather large kind
type parameters, but if the compiler detected the overflow
the abort would happen on an uncommented line, and if the
compiler didn't detect the overflow there would be a chance
of about 1 ppb of generating a valid kind type parameter.
Lots more likely that the compiler would die from an ICE, but
why worry when we can guard against all these possibilities?
module mykinds
implicit none
integer, parameter :: ik2 = selected_int_kind(4)
integer, parameter :: test2a = -abs(16-bit_size(1_ik2))
integer, parameter :: test2b = (1+sign(1,test2a))/2*kind(.TRUE.)+ &
(1-sign(1,test2a))/2*(-1)
logical(test2b) :: test2c ! Fails if bit_size(1_ik2) /= 16
! private test2a, test2b, test2c
end module mykinds
program test
use mykinds
implicit none
write(*,*) ik2, test2a, test2b
end program test
--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end
|
|
|
|
|