Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get the upper-/lower machine-word of a double according to IEEE 754 (ansi-c)?
    primarykey
    data
    text
    <p>i want to use the sqrt implementation of <a href="http://www.netlib.org/fdlibm/" rel="nofollow">fdlibm</a>.<br> This implementation defines (according to the endianess) some macros for accessing the <strong>lower/upper 32-bit of a double</strong>) in the following way (here: only the little-endian-version):</p> <pre><code>#define __HI(x) *(1+(int*)&amp;x) #define __LO(x) *(int*)&amp;x #define __HIp(x) *(1+(int*)x) #define __LOp(x) *(int*)x </code></pre> <p>The readme of flibm is saying the following (a little bit shortened)</p> <pre><code>Each double precision floating-point number must be in IEEE 754 double format, and that each number can be retrieved as two 32-bit integers through the using of pointer bashing as in the example below: Example: let y = 2.0 double fp number y: 2.0 IEEE double format: 0x4000000000000000 Referencing y as two integers: *(int*)&amp;y,*(1+(int*)&amp;y) = {0x40000000,0x0} (on sparc) {0x0,0x40000000} (on 386) Note: Four macros are defined in fdlibm.h to handle this kind of retrieving: __HI(x) the high part of a double x (sign,exponent,the first 21 significant bits) __LO(x) the least 32 significant bits of x __HIp(x) same as __HI except that the argument is a pointer to a double __LOp(x) same as __LO except that the argument is a pointer to a double If the behavior of pointer bashing is undefined, one may hack on the macro in fdlibm.h. </code></pre> <p><em>I want to use this implementation and these macros with the <a href="http://www.cprover.org/cbmc/" rel="nofollow">cbmc</a> model checker, which should be conformable with ansi-c</em>.<br> I don't know exactly whats wrong, but the following example shows that these macros aren't working (little-endian was chosen, 32-bit machine-word was chosen):</p> <pre><code>temp=24376533834232348.000000l (0100001101010101101001101001010100000100000000101101110010000111) high=0 (00000000000000000000000000000000) low=67296391 (00000100000000101101110010000111) </code></pre> <p>Both seem to be wrong. High seems to be empty for every value of temp.</p> <p><strong>Any new ideas for accessing the both 32-words with ansi-c?</strong></p> <p><strong>UPDATE:</strong> Thanks for all your answers and comments. All of your proposals worked for me. For the moment i decided to use "R.."s version and marked this as favorite answer because it seems to be the most robust in my tool regarding endianness.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload