Hi Damian - I do have one question for you about this. The C function frexp breaks up a floating point number into a normalized fraction (stored as a double) and an exponent.
Do you know how to convert that behavior to returning the mantissa as an integer? Is it important to you to get an integer mantissa versus a normalized fraction? Do you know why the fractional mantissa strategy was chosen for C? I think it would be straightforward to implement something in the runtime that calls these C functions. Alternatively, we could use the implementation similar to what you have described as some C functions (that are inline) in the runtime. Either way, I think that the best approach here is to implement it as part of the runtime (rather than give Chapel the ability to use C unions, e.g.). You could implement it in C for now. I suppose an alternative would be to use the Chapel support for C interoperability to memcpy from the real(64) to a uint(64) and then do your shifting and extracting. I still think it would be better to do the whole operation in C myself. Thanks, -michael P.S. I'm hoping that the hex floats patch will go in this week... On 5/17/15, 2:59 AM, "Damian McGuckin" <[email protected]> wrote: > >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 ------------------------------------------------------------------------------ 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
