On 2020-07-13 at 08:23, Greg Wooledge wrote: > On Mon, Jul 13, 2020 at 06:47:51AM -0400, The Wanderer wrote: > >> In some contexts it could even need fewer; for example, calc (as >> shipped in Debian) provides the built-in function 'pi()', which >> takes a precision - expressed as a value between zero and one - and >> returns pi to that level of precision. > > I do not understand this description. How many decimal places do > you get for a precision of, say, 0.5? (It turns out I got the specification of what the precision can be expressed as wrong, and "precision" may not be the correct term for it anyway; see below.) I don't understand the full algorithm myself, but the output seems coherent: $ calc C-style arbitrary precision calculator (version 2.12.7.2) Calc is open software. For license details type: help copyright [Type "exit" to exit, or "help" for help.] ; pi(.5) 3 ; pi(.1) 3.1 ; pi(.9) 2.7 ; pi(.05) 3.15 ; pi(.0005) 3.1415 ; pi(.00005) 3.1416 ; pi(.00001) 3.14159 ; pi(.00009) 3.1416 I generally just use something like 'pi(.0000000000000001)' (i.e., hold down the 0 key for a while in between . and 1), and that produces all the precision I could really care for. The limit that gets printed (at least with default configuration) appears to be ; pi(.0000000000000000000000000000000000000000000000000001) ~3.14159265358979323846 and you can get that same visible result with a much shorter precision value. I expect that there are configuration settings which will increase the displayed precision, but I've never needed to find them. Also, it turns out that it accepts values >=1 and <=0 as well: ; pi(5) 5 ; pi(10) 0 ; pi(50) 0 ; pi(3) 3 ; pi(4) 4 ; pi(2) 4 ; pi(-1) 3 ; pi(0) zero epsilon value for pi ; pi(1) 3 The results just aren't very useful. >> The list of built-in functions in the bc man page is very short, >> and doesn't include any such thing, so unless something has added >> one without the man page getting updated anything that needs to use >> pi is going to take more typing than with calc. > > True. But it's not a *huge* amount of typing. > > unicorn:~$ bc -l Yep - as soon as I saw someone point out what this flag did, I figured this would be in there somewhere. (I didn't figure it out from looking the flag up in the man page, but that's me.) > bc 1.07.1 > Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc. > This is free software with ABSOLUTELY NO WARRANTY. > For details type `warranty'. > 4*a(1) > 3.14159265358979323844 Definitely convenient, but also requires knowing more about math than I've managed to internalize over the decades to figure out. I would not have thought of multiplying by the arctangent of 1 (or of anything) to arrive at pi. -- The Wanderer The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore all progress depends on the unreasonable man. -- George Bernard Shaw
Attachment:
signature.asc
Description: OpenPGP digital signature