Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!brutus.cs.uiuc.edu!ginosko!uunet!munnari.oz.au!cs.mu.oz.au!ok From: ok@cs.mu.oz.au (Richard O'Keefe) Newsgroups: comp.lang.c,comp.sys.super Subject: Re: Type punning in C Message-ID: <2386@munnari.oz.au> Date: 11 Oct 89 05:29:55 GMT References: <475@idacrd.UUCP> <1989Oct10.185851.6490@agate.berkeley.edu> Sender: news@cs.mu.oz.au Lines: 32 In article <1989Oct10.185851.6490@agate.berkeley.edu>, jerry@violet.berkeley.edu ( Jerry Berkman ) writes: : 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? : Why not use equivalence? : INTEGER I : REAL X, IX : EQUIVALENCE (X,IX) Because he was asking how to do it in C. I understand that the original problem was something that could be expressed quite clearly and simply as an ordinary C arithmetic expression operating exclusively on integers, and that straightforward C code would _work_ on the Cray, but because some operation (bitwise shifts?) didn't have a vector equivalent it wouldn't vectorise. But a hairy hack involving floats _would_ vectorise because the Cray system is good at vectorising float operations. The interesting point here is that there are a lot of things you can do IF you have the functions required and recommended in the IEEE 754 standard. For example, if there is some reason why you want to avoid p << i use (int) scalb((float)p, i) p >> j use (int) scalb((float)p, -j) This is why I think that it would be interesting for people with such problems (and this includes Herman Rubin) to give us more detail about the problem they are really trying to solve (e.g. the original poster's problem was "how do I get results equal to these in a way that will vectorise on a Cray?"). It may be that some of these problems have solutions which are less machine-specific than hand-crafted bit-twiddling, or would be if functional equivalents of the IEEE functions were provided.