From owner-freebsd-questions@FreeBSD.ORG Tue Apr 11 23:37:01 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 956A316A401 for ; Tue, 11 Apr 2006 23:37:01 +0000 (UTC) (envelope-from herriojr@gmail.com) Received: from nproxy.gmail.com (nproxy.gmail.com [64.233.182.189]) by mx1.FreeBSD.org (Postfix) with ESMTP id C99E943D46 for ; Tue, 11 Apr 2006 23:37:00 +0000 (GMT) (envelope-from herriojr@gmail.com) Received: by nproxy.gmail.com with SMTP id m18so984252nfc for ; Tue, 11 Apr 2006 16:37:00 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Ut8E0ykNMsFoanx5Xuz1Ovp2EOERGMuPVOg+oWfzSpJoEtdgnSmpbxzVMSqQaiHBgO34Igt+aWi2qv7bIMnD0V0EzuljUi85kR+bVNQRGUF3j3Rx0uCnigWYfZaIVni7NsIB1mOsRmcMcnGee1AjknJdlL249fD+4XtjnNkfXuE= Received: by 10.49.93.4 with SMTP id v4mr924619nfl; Tue, 11 Apr 2006 16:36:59 -0700 (PDT) Received: by 10.49.29.3 with HTTP; Tue, 11 Apr 2006 16:36:59 -0700 (PDT) Message-ID: <6a56d69c0604111636m5d302f8doe62061e856831d4d@mail.gmail.com> Date: Tue, 11 Apr 2006 23:36:59 +0000 From: "Jonathan Herriott" To: "Nicolas Blais" In-Reply-To: <200604111935.14023.nb_root@videotron.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <6a56d69c0604111554o587ce2c5ha1ff4ea20bbab0a4@mail.gmail.com> <443C3AA7.4020500@freebsd.org> <200604111935.14023.nb_root@videotron.ca> Cc: Andy Reitz , freebsd-questions@freebsd.org Subject: Re: pow function working unexpectedly X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Apr 2006 23:37:01 -0000 Yes, thank you. I wasn't going to report it as a bug after you pointed out my blatant mistake. Thanks again for the info. Jon On 4/11/06, Nicolas Blais wrote: > On Tuesday 11 April 2006 19:24, Colin Percival wrote: > > Andy Reitz wrote: > > > So, clearly, something is optimizing the pow() function away when the > > > arguments are hard-coded lvalues, instead of varibles. > > > > > > Now, what that thing *is*, I don't know. > > > > The C compiler precomputes constant expressions; your "pow(2,3)" is > > being rewritten to "8" by the compiler. Similarly, if you write > > "1 + 2 / 3 + 4 * 5 - 6", the C compiler will turn this into "15" > > rather than producing a series of instructions which computes the > > expression. > > > > When you reference variables, this optimization isn't possible, since > > those variables might be modified before you reach the line where > > they are used. (Obviously this doesn't happen in your program, but > > the compiler isn't smart enough to figure that out.) > > > > Colin Percival > > +1. The compiler sees constants differently from variables (which reside = in > a > memory space). With the constant, the optimizer can rewrite the equation > with > its answer. > > Anyhow, it can't be seen as a bug because you should include the math > library > whenever you're using a function from it (see man pow). Therefore, if you > would have included the library in the first place, you would have never > found this 'oddity'. > > Nicolas. > > -- > FreeBSD 7.0-CURRENT #1: Sat Apr 8 21:33:25 EDT 2006 > root@clk01a:/usr/obj/usr/src/sys/CLK01A > PGP? : http://www.clkroot.net/security/nb_root.asc > >