Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #197734

Re: Calculator with "tapes"

From Greg Wooledge <wooledg@eeg.ccf.org>
Newsgroups linux.debian.user
Subject Re: Calculator with "tapes"
Date 2018-07-17 15:00 +0200
Message-ID <wcxKa-hJ-7@gated-at.bofh.it> (permalink)
References <wcf0R-61U-5@gated-at.bofh.it> <wcvyF-7xd-5@gated-at.bofh.it> <wcwuK-84X-7@gated-at.bofh.it> <wcxh7-7X-1@gated-at.bofh.it> <wcxAt-eu-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


People are talking about manually setting the "scale" variable in bc,
and using small values like 3 for it.

Please note that this the scale variable is NOT just used for rounding of
final results for display.  It's used for internal precision of storage
of ALL intermediate results.  Using a small scale can and will distort
your results.

I learned this the hard way.

Need an example?  OK.  Let's calculate 1.4 to the power of 50.5.

$ bc -l
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 
1.4^50.5
Runtime warning (func=(main), adr=12): non-zero scale in exponent
20248916.23976437135118764865

As the warning indicates, you can't actually use a non-integer exponent
with the ^ operator in bc -l.  But you can rewrite it with a logarithm
and an exponent.  So let's do that.

e(50.5*l(1.4))
23958840.79914949898175198920

OK, that's too many digits, so now let's do the same thing with scale=3:

scale=3
e(50.5*l(1.4))
23394230.731

The result is substantially different.  This is because the scale is
used internally, NOT just on the final result.

If you use bc, always just use "bc -l" which sets a scale of 20, and
leave it set that way.  If you need a prettier result, take the result
from bc -l and use printf to round it.  Or use a programming language
that has floating point arithmetic support.

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Calculator with "tapes" Ken Heard <kenslists@teksavvy.com> - 2018-07-16 19:00 +0200
  Re: Calculator with "tapes" Joe <joe@jretrading.com> - 2018-07-16 19:10 +0200
    Re: Calculator with "tapes" Jude DaShiell <jdashiel@panix.com> - 2018-07-16 19:50 +0200
  Re: Calculator with "tapes" Boyan Penkov <boyan.penkov@gmail.com> - 2018-07-16 19:20 +0200
  Re: Calculator with "tapes" Nicholas Geovanis <nickgeovanis@gmail.com> - 2018-07-16 19:20 +0200
  Re: Calculator with "tapes" Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2018-07-16 19:50 +0200
  Calculator with "tapes" "Thomas Schmitt" <scdbackup@gmx.net> - 2018-07-16 20:00 +0200
  Re: Calculator with "tapes" Eric S Fraga <e.fraga@ucl.ac.uk> - 2018-07-16 23:10 +0200
  Re: Calculator with "tapes" Ben Caradoc-Davies <ben@transient.nz> - 2018-07-17 02:00 +0200
  Re: Calculator with "tapes" Zenaan Harkness <zenaan@freedbms.net> - 2018-07-17 02:20 +0200
    Re: Calculator with "tapes" Stefan Krusche <linux@stefan-krusche.de> - 2018-07-17 03:10 +0200
      Re: Calculator with "tapes" Curt <curty@free.fr> - 2018-07-17 11:20 +0200
        Re: Calculator with "tapes" Stefan Krusche <linux@stefan-krusche.de> - 2018-07-17 12:40 +0200
          Re: Calculator with "tapes" Curt <curty@free.fr> - 2018-07-17 13:40 +0200
            Re: Calculator with "tapes" Stefan Krusche <linux@stefan-krusche.de> - 2018-07-17 14:30 +0200
              Re: Calculator with "tapes" Curt <curty@free.fr> - 2018-07-17 14:50 +0200
                Re: Calculator with "tapes" Greg Wooledge <wooledg@eeg.ccf.org> - 2018-07-17 15:00 +0200
      Re: Calculator with "tapes" Zenaan Harkness <zenaan@freedbms.net> - 2018-07-23 04:30 +0200
        Re: Calculator with "tapes" Curt <curty@free.fr> - 2018-07-23 09:30 +0200
        Re: Calculator with "tapes" Stefan Krusche <linux@stefan-krusche.de> - 2018-07-23 13:10 +0200
          Re: Calculator with "tapes" Stefan Krusche <linux@stefan-krusche.de> - 2018-07-23 13:20 +0200
            Re: Calculator with "tapes" <tomas@tuxteam.de> - 2018-07-23 13:30 +0200
              Re: Calculator with "tapes" Stefan Krusche <linux@stefan-krusche.de> - 2018-07-23 13:50 +0200
          Re: Calculator with "tapes" <tomas@tuxteam.de> - 2018-07-23 13:30 +0200
  Re: Calculator with "tapes" Piotr <zaxonxp45@gmail.com> - 2018-07-17 07:30 +0200
  Re: Calculator with "tapes" John Darrah <xyllyx@gmail.com> - 2018-07-23 16:50 +0200

csiph-web