help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with Hand-Optimized Assembly


From: Tim Roberts
Subject: Re: Help with Hand-Optimized Assembly
Date: Wed, 28 Mar 2012 18:29:59 -0000

Terje Mathisen <"terje.mathisen at tmsw.no"@giganews.com> wrote:
>
>Inline C isn't too hard to write:

Have you tried this code?

>inline double delta(double th1, th2)
>{
>     static double pi = 3.14159265357989;
>     static double zero_or_twopi[2] = {0, 3.14159265357989*2};
>     static double absmask = (double) 0x7fffffffffffffff;

That doesn't do what you think it does.  That cast converts the constant to
floating point -- it doesn't just copy the bits.  There are only 56 bits of
mantissa available in a double, so some of your bits get lost.

>     static double signmask = -0.0;
>
>     double diff = th1-th2;
>     double adiff = (double) ((int64_t) diff & (int64_t) absmask);

Again here, this is going to convert diff to an integer, which means you'll
lose any bits to the right of the decimal point.  It's not a bitwise copy.

To do bitwise manipulation, you need to fool the compiler:
    double adiff = *(double*)(*(int64_t*)&diff & *(int64_t*)&absmask);

>     adiff = (double) ((int64_t) adiff ^
>        ((int64_t) signmask & (int64_t) diff));

Same problem occurs here.
-- 
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]