From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29195 invoked by alias); 11 Dec 2002 13:24:22 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 29187 invoked from network); 11 Dec 2002 13:24:21 -0000 Received: from unknown (HELO smtp-relay-2.adobe.com) (192.150.11.2) by sources.redhat.com with SMTP; 11 Dec 2002 13:24:21 -0000 Received: from inner-relay-2.corp.adobe.com (inner-relay-2 [153.32.1.52]) by smtp-relay-2.adobe.com (8.12.3/8.12.3) with ESMTP id gBBDOIPK002071 for ; Wed, 11 Dec 2002 05:24:18 -0800 (PST) Received: from iplan-mn.corp.adobe.com (iplan-mn.corp.adobe.com [130.248.25.5]) by inner-relay-2.corp.adobe.com (8.12.3/8.12.3) with ESMTP id gBBDOC4W005183 for ; Wed, 11 Dec 2002 05:24:12 -0800 (PST) Received: from [130.248.25.220] ([153.32.12.150]) by iplan-mn.corp.adobe.com (Netscape Messaging Server 4.15 mn Jul 11 2001 16:32:57) with ESMTP id H6YIKB00.2P0; Wed, 11 Dec 2002 07:24:11 -0600 User-Agent: Microsoft-Entourage/10.0.0.1331 Date: Wed, 11 Dec 2002 05:24:00 -0000 Subject: Re: Casting and Optimization Flags From: John Love-Jensen To: Colin Law , Message-ID: In-Reply-To: <3DF72E47.2080806@elec.gla.ac.uk> Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit X-SW-Source: 2002-12/txt/msg00130.txt.bz2 Hi Colin, Floating point numbers are not exact numbers, and slight rounding and/or truncation issues should be expected. There are much better (i.e., exacting) algorithms to calculate your desired value width. On modern architectures with 1-cycle FPU log10 and division, the performance will be similar. On slightly older architectures, these algorithms are more efficient. Check out this excellent Stanford page of Bit Twiddling Hacks, kudos to Sean Eron Anderson. In particular, the "Find the log base 2 of an N-bit integer in O(lg(N)) operations". Or perhaps the "Round up to the next highest power of 2" is more suited to your needs. Note: I'd avoid the "Find integer log base 2 of a 32-bit IEEE float", since the algorithm presumes (and relies upon) the IEEE layout in memory. But that's because I like to write platform agnostic C++ code. --Eljay