float-equal warnings

Gary E. Miller gem at rellim.com
Mon Apr 10 20:22:27 UTC 2017


Yo All!

Mark asked me to dig deeper.

On Sun, 9 Apr 2017 19:06:53 -0700
"Gary E. Miller" <gem at rellim.com> wrote:

> > Comparing against LOGTOD(-31) will fail for any value less than
> > ~0.2ns (the minimum l_fp fraction).  
> 
> Yup.  Except the results is a constant, and having to compute a log
> every time on a constant is a bit watesful.


So I made a test:

    #include <math.h>
    #define LOGTOD(a)	ldexp(1., (int)(a)) /* log2 to double */
    int main( int argc, char ** argv)
    {
	return (int)LOGTOD(1e-9);
    }

gcc -g test.c -o test
gdb test
disasssemble main:

    Dump of assembler code for function main:
       0x00000000004004b6 <+0>:	push   %rbp
       0x00000000004004b7 <+1>:	mov    %rsp,%rbp
       0x00000000004004ba <+4>:	mov    %edi,-0x4(%rbp)
       0x00000000004004bd <+7>:	mov    %rsi,-0x10(%rbp)
       0x00000000004004c1 <+11>:	mov    $0x1,%eax
       0x00000000004004c6 <+16>:	pop    %rbp
       0x00000000004004c7 <+17>:	retq   
    End of assembler dump.

So  I'm shocked, gcc made LOGTOD(1e-9) a simple binary constant.

RGDS
GARY
---------------------------------------------------------------------------
Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97703
	gem at rellim.com  Tel:+1 541 382 8588

	    Veritas liberabit vos. -- Quid est veritas?
    "If you can’t measure it, you can’t improve it." - Lord Kelvin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://lists.ntpsec.org/pipermail/devel/attachments/20170410/e6bae0b9/attachment.bin>


More information about the devel mailing list