Re: Multiple return values

Robert.Harley@inria.fr (Robert Harley)
22 Apr 1997 21:12:26 -0400

          From comp.compilers

Related articles
[10 earlier articles]
Re: Multiple return values danwang@dynamic.CS.Princeton.EDU (1997-04-20)
Re: Multiple return values smcadams@sprynet.com (steve mcadams) (1997-04-20)
Re: Multiple return values tiggr@es.ele.tue.nl (1997-04-20)
Re: Multiple return values hrubin@stat.purdue.edu (1997-04-20)
Re: Multiple return values fjh@mundook.cs.mu.OZ.AU (1997-04-22)
Re: Multiple return values roy@earthlight.co.nz (1997-04-22)
Re: Multiple return values Robert.Harley@inria.fr (1997-04-22)
Re: Multiple return values jashley@eecs.ukans.edu (Mike Ashley) (1997-04-22)
Re: Multiple return values burley@tweedledumb.cygnus.com (Craig Burley) (1997-04-22)
Re: Multiple return values albaugh@agames.com (1997-04-22)
Re: Multiple return values tiggr@es.ele.tue.nl (1997-04-30)
Re: Multiple return values jch@hazel.pwd.hp.com (John Haxby) (1997-05-04)
Re: Multiple return values jan@digicomp.com (Jan Galkowski) (1997-05-04)
[13 later articles]
| List of all articles for this month |
From: Robert.Harley@inria.fr (Robert Harley)
Newsgroups: comp.compilers,comp.lang.misc
Date: 22 Apr 1997 21:12:26 -0400
Organization: I.N.R.I.A Rocquencourt
References: 97-04-091 97-04-109 97-04-138
Keywords: design

hrubin@stat.purdue.edu (Herman Rubin) writes:
>[...]
>A good example of something which is quite easy in hardware but
>difficult in software, and which is now often not available on
>computers, is
>
> (exp, mant) =UP. float;
>
>This would be the unpacking operation. [...]


Difficult? Not available? What about something like:


    unsigned u;
    int exp, mant;
    union { unsigned u; float f; } uf;


    uf.f = f; u = uf.u;
    exp = (int)(u>>23 & 255U)-127;
    mant = (int)(u &~ 0xFF000000U | 0x800000U);
    if (u>>31) mant = -mant;


?
Sticking to the topic of the thread, wrap this up in:




typedef struct { int exp, mant; } pair;


static pair unpack(float f) {
    pair p;


    [...as above...]


    p.exp = exp; p.mant = mant;
    return p;
} /* end unpack */


GCC will optimise this just fine.


-- Rob.
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.