or more specifically, extracting the components of such numbers, or 
assembling those numbers from their components.

Among other things, I want to grab the mantissa from a 64bit (IEEE784) 
floating point number, i.e. the top 12 bits of a floating point number 
(excluding the sign bit) and I want it inline without the overhead of a 
function call, i.e. if it were legal, I would like to do the following:

        inline proc rmantissa(r : real) : int
        {
            union ieee784 { var rv : real; var iv : int; };
            var x : ieee784;

            // copy the floating point number 'r' into 'x'
            x.rv = r;
            // grab the top 12 bits but strip off the sign bit
            return (x.iv >> 52) & 0x7ff;
        }

As Chapel enforces a PASCAL-style concept on unions which allows access to 
only those fields that have data currently in them, my above codes causes 
a run-time error. A C-style approach where the names are pretty much just 
aliases for one another would not.

Is there workaround, and if so, what is it?

Once we have this, we can then write the 2 routines ...

   inline proc ieee754unpack(var r : real) : (int, int, int)

&

   inline proc ieee754pack(sign : int, exponent : int, mantissa : int) : real

which will respectively

        unpack/split an IEEE754 floating point number into a sign,
        exponent and mantissa, all three being returned as integers
        the exponent in raw (or denormalized) form,

and
        build an IEEE754 floating point number from a sign, exponent
        and mantissa, all three being given/passed as integers with
        the exponent being raw or de-normalized

as well as routines to just extract/replace the individual components.

There are obviously more things that one needs to do with IEEE754
numbers but I will leave it there for now.

Regards - Damian

Pacific Engineering Systems International, 277-279 Broadway, Glebe NSW 2037
Ph:+61-2-8571-0847 .. Fx:+61-2-9692-9623 | unsolicited email not wanted here
Views & opinions here are mine and not those of any past or present employer

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users

Reply via email to