Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!apple!agate!violet.berkeley.edu!jerry From: jerry@violet.berkeley.edu ( Jerry Berkman ) Newsgroups: comp.lang.c,comp.sys.super Subject: Re: Type punning in C Message-ID: <1989Oct10.185851.6490@agate.berkeley.edu> Date: 10 Oct 89 18:58:51 GMT References: <475@idacrd.UUCP> Sender: usenet@agate.berkeley.edu (USENET Administrator;;;;ZU44) Reply-To: jerry@violet.berkeley.edu ( Jerry Berkman ) Organization: University of California, Berkeley Lines: 23 In article <475@idacrd.UUCP> desj@idacrd.UUCP (David desJardins) writes: > Does anyone have any ideas on how one should go about converting an >integer to the floating-point number with the same bit pattern? >The best way I have found to do this in FORTRAN is to write > INTEGER I > REAL X > X = OR (I, 0). >(The Cray FORTRAN compiler optimizes out the trivial OR instruction.) > -- David desJardins Why not use equivalence? INTEGER I REAL X, IX EQUIVALENCE (X,IX) IX = I The Fortran standard specifies that a REAL and INTEGER occupy the same space. The only problem is this might fool some optimizers. - Jerry Berkman jerry@violet.berkeley.edu