From owner-freebsd-questions@FreeBSD.ORG Fri Dec 3 13:41:20 2004 Return-Path: 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 D764216A4CE for ; Fri, 3 Dec 2004 13:41:20 +0000 (GMT) Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3097C43D3F for ; Fri, 3 Dec 2004 13:41:20 +0000 (GMT) (envelope-from malcolm.kay@internode.on.net) Received: from beta.home (ppp250-130.lns2.adl2.internode.on.net [203.122.250.130])iB3DfH4Y031758; Sat, 4 Dec 2004 00:11:18 +1030 (CST) From: Malcolm Kay Organization: at home To: "Florian Hengstberger" , FreeBSD mailinglist Date: Sat, 4 Dec 2004 00:11:17 +1030 User-Agent: KMail/1.5.4 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200412040011.17130.malcolm.kay@internode.on.net> Subject: Re: Floating Point Arithmetic X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Dec 2004 13:41:21 -0000 On Fri, 3 Dec 2004 07:23 pm, Florian Hengstberger wrote: > Hi! > > I tried to figure out the capability of double: > so I calculated > > d=2**n (with a for-loop) > > increasing n step by step. > Of course I get a floating point exception when > d is bigger than 10**308. > But what makes me wondering is the fact that printing > printf("%lf",d) gives me the full range of numbers! > > Calculating 2**1000 and I got the correct number > with all (!!) digits. (I cross-checked the digits with python.) > This is unexpected because sizeof(double) on my machine is 8, > and so I thought that the limit for the correct representation > is 2**(8*8). > (Actually the limit should be - meeting the IEEE standard - > 2**52, the space reserved for representing the fraction of > a floating point number.) > Anyway I can calculate 2**n, with n up to 1023 exact. > Why is this??? Just think about it. If you have an integer power of two all the discarded significant bits were zero anyway so the representation is exact. But try 2**1000-1 Malcolm