For Programmers: Free Programming Magazines  


Home > Archive > Fortran > December 2005 > Re: printing logical variables as "true" and "false"









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: printing logical variables as "true" and "false"
James Van Buskirk

2005-11-29, 7:01 pm

"Paul Van Delst" <Paul.vanDelst@noaa.gov> wrote in message
news:dmi229$1on$1@news.nems.noaa.gov...

> Slightly off topic, but in IDL:


> F => Zero and even values (e.g. -4, -2, 0, 2, 4, etc)
> T => Odd non zero values (e.g. -3, -1, 1, 3, 5, etc)


> (which I can't stand, btw.)


Actually, the DEC family of Fortran compilers did this, too.
The massive advantage of the LSB defining LOGICAL values like
this is that bitwise logical operations have the effect of
Fortran LOGICAL operations. I consider it probable that
many old-school compilers (i.e. ones that have roots predating
MIL-STD 1753) behave this way so as to permit masking
expressions. The difference in behavior becomes apparent
when mixed-language programming of bit-swizzling via
TRANSFER. One can get ugly results when Fortran processors
use the C-style (value of x is "x /= 0") int as boolean:
you can have both a and b evaluate as .TRUE., but a .AND. b
evaluate as .FALSE.

program logical_test
implicit none
logical a, b

a = transfer(1,a)
b = transfer(2,b)
write(*,*) a, b, a .AND. b
end program logical_test

Output with LF95 v. 5.70f:

T T F

Output with CVF v. 6.6C3

T F F

Output with g95 gcc version 4.0.1 (g95!) Sep 1 2005:

T T T

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


Andy Mai

2005-11-29, 7:01 pm

In article < WqadnVLsSpFkPBHenZ2dnUVZ_tmdnZ2d@comcast
.com>,
James Van Buskirk <not_valid@comcast.net> wrote:
>
>--
>write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
>6.0134700243160014d-154/),(/'x'/)); end



Are you aware that running the Fortran program in your signature
produces different results with various compilers?

Intel Fortran 8.0 on Fedora Core 4:
rjihad1@comcast.net

Sun Fortran on Solaris:
@1dahijr.tsacmoc ten

XLF on IBM RS/6000:
@1dahijr¼¨Ê¼l0_a.tsacmoc*Ó°[©ýä ten`~½

MIPSpro f90 on SGI:
@1dahijr.tsacmoc ten

Compaq f90 on Compaq SC45:
rjihad1@comcast.net

Andy
James Van Buskirk

2005-11-29, 7:01 pm

"Andy Mai" <mai@mer.ucar.edu> wrote in message
news:dmii1h$pq6$1@mer.ucar.edu...

> Are you aware that running the Fortran program in your signature
> produces different results with various compilers?


I may have to change my email address and not include it
in my sig.f90 file because you printed it in public. Thanks
a lot.

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


Jan Vorbrüggen

2005-12-08, 7:59 am

> Are you aware that running the Fortran program in your signature
> produces different results with various compilers?


That's the difference between little- and big-endian machines, with
an uninitialized string on the IBM thrown in for good measure.

Jan
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com