Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Learning functions; roots of the quadratic; two return values Date: Wed, 07 Oct 2015 16:23:28 -0700 Organization: None to speak of Lines: 26 Message-ID: References: <623fef72-989a-4973-9d04-b1a867a00703@googlegroups.com> <5611ccfd$0$3060$426a34cc@news.free.fr> <5613071A.2070609@verizon.net> <20151007051930.3973122b@maxa-pc> <20151008005326.47e5ac1f@maxa-pc> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="31158"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18UBs/x9ZJoah3MnBILLY9d" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:gTfHXV8dkQH96wgwvvzWHn5hbDA= sha1:k1bREvEKmY6kirSn1+ATZJ5/cHQ= Xref: csiph.com comp.lang.c:72163 Melzzzzz writes: > On Wed, 07 Oct 2015 09:12:33 -0700 > Keith Thompson wrote: [...] >> The behavior of the sqrt() function is defined by the standard. A >> compiler can take advantage of the fact that calling sqrt() twice with >> the same argument will yield the same result both times, and will not >> have side effects. > > Yes, I see that compiler (gcc) takes advantage of knowing contents of > sqrt, but there is some weird constraint that make it generate calls > for several sqrts anyway. That is it does not calls function first, > rather it executes sqrt instruction directly, but then it checks > result with itself (ucomisd) and if parity flag is set (unordered) it > calls sqrt then checks result again and if parity calls sqrt again. > This code is not present if -ffast-math or -Ofast flag is present. I have no idea. The standard requires a call to the standard sqrt() function to behave in a certain way. A compiler is free to do whatever it likes to achieve that effect. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"