From owner-freebsd-questions@FreeBSD.ORG Fri Nov 5 19:25:21 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D72A7106566B for ; Fri, 5 Nov 2010 19:25:21 +0000 (UTC) (envelope-from alex@stangl.us) Received: from stangl.us (stangl.us [66.93.193.95]) by mx1.freebsd.org (Postfix) with ESMTP id A3A888FC18 for ; Fri, 5 Nov 2010 19:25:21 +0000 (UTC) Received: from scout.stangl.us (localhost [127.0.0.1]) by scout.stangl.us (Postfix) with ESMTP id E251EB895; Fri, 5 Nov 2010 14:25:20 -0500 (CDT) X-Virus-Scanned: amavisd-new at stangl.us Received: from stangl.us ([127.0.0.1]) by scout.stangl.us (scout.stangl.us [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FHdEM599dEXz; Fri, 5 Nov 2010 14:25:19 -0500 (CDT) Received: by scout.stangl.us (Postfix, from userid 1001) id DFF4EB872; Fri, 5 Nov 2010 14:25:19 -0500 (CDT) Date: Fri, 5 Nov 2010 14:25:19 -0500 From: Alex Stangl To: Arthur Bela Message-ID: <20101105192519.GA78113@scout.stangl.us> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i Cc: FreeBSD Mailing list Subject: Re: how to generate pi in c 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: Fri, 05 Nov 2010 19:25:21 -0000 On Fri, Nov 05, 2010 at 05:40:39PM +0100, Arthur Bela wrote: > Does anyone has a "generate-pi.c" source code? Search for pi spigot algorithm. Here is a tiny C program from Jeremy Gibbon's Unbounded Spigot paper (due to Dik Winter and Achim Flammenkamp): a[52514],b,c=52514,d,e,f=1e4,g,h;main(){for(;b=c-=14;h=printf("%04d", e+d/f))for(e=d%=f;g=--b*2;d/=g)d=d*b+f*(h?a[b]:f/5),a[b]=d%--g;} This produces the first 15,000 digits concisely, but is obfuscated. If you need an unbounded number of digits, search out the spigot algorithm papers. Alex