Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

All syllogisms have three parts, therefore this is not a syllogism.


devel / comp.unix.shell / Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

SubjectAuthor
* Removing non-significant zeros from the fractional portion of aOğuz
+* Re: Removing non-significant zeros from the fractional portion of aEli the Bearded
|+* Re: Removing non-significant zeros from the fractional portion of a number in PODan Espen
||`- Re: Removing non-significant zeros from the fractional portion of a number in POBen Bacarisse
|`* Re: Removing non-significant zeros from the fractional portion of aOğuz
| +- Re: Removing non-significant zeros from the fractional portion of a number in POKeith Thompson
| +* Re: Removing non-significant zeros from the fractional portion of aAndy Walker
| |`* Re: Removing non-significant zeros from the fractional portion of aOğuz
| | `* Re: Removing non-significant zeros from the fractional portion of a number in POBen Bacarisse
| |  `- Re: Removing non-significant zeros from the fractional portion of aOğuz
| +* Re: Removing non-significant zeros from the fractional portion of aLew Pitcher
| |`- Re: Removing non-significant zeros from the fractional portion of aOğuz
| `- Re: Removing non-significant zeros from the fractional portion of aJanis Papanagnou
+- Re: Removing non-significant zeros from the fractional portion of aChris Elvidge
`* Re: Removing non-significant zeros from the fractional portion of amarrgol
 `* Re: Removing non-significant zeros from the fractional portion of aEli the Bearded
  +* Re: Removing non-significant zeros from the fractional portion of a number in PODan Espen
  |+* Re: Removing non-significant zeros from the fractional portion of a number in POEli the Bearded
  ||`- Re: Removing non-significant zeros from the fractional portion of a number in POKeith Thompson
  |`* Re: Removing non-significant zeros from the fractional portion of amarrgol
  | `- Re: Removing non-significant zeros from the fractional portion of a number in PODan Espen
  `- Re: Removing non-significant zeros from the fractional portion of amarrgol

1
Removing non-significant zeros from the fractional portion of a number in POSIX bc

<85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4345&group=comp.unix.shell#4345

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:6214:706:: with SMTP id b6mr7162072qvz.29.1631471965182;
Sun, 12 Sep 2021 11:39:25 -0700 (PDT)
X-Received: by 2002:a05:620a:2298:: with SMTP id o24mr6880386qkh.235.1631471964985;
Sun, 12 Sep 2021 11:39:24 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sun, 12 Sep 2021 11:39:24 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=85.103.121.52; posting-account=RbOzpwoAAACSDI6OO1wVarfPakNstxUl
NNTP-Posting-Host: 85.103.121.52
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
Subject: Removing non-significant zeros from the fractional portion of a
number in POSIX bc
From: oguzisma...@gmail.com (Oğuz)
Injection-Date: Sun, 12 Sep 2021 18:39:25 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 7
 by: Oğuz - Sun, 12 Sep 2021 18:39 UTC

For example:

f(1.20000) => 1.2
f(100) => 100
f(1.0234) => 1.0234
f(123.00) => 123

How would you implement such a function as f in bc?

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<eli$2109121749@qaz.wtf>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4346&group=comp.unix.shell#4346

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix5.panix.com!qz!not-for-mail
From: *...@eli.users.panix.com (Eli the Bearded)
Newsgroups: comp.unix.shell
Subject: Re: Removing non-significant zeros from the fractional portion of a
number in POSIX bc
Date: Sun, 12 Sep 2021 21:49:23 -0000 (UTC)
Organization: Some absurd concept
Message-ID: <eli$2109121749@qaz.wtf>
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Sun, 12 Sep 2021 21:49:23 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="panix5.panix.com:166.84.1.5";
logging-data="15037"; mail-complaints-to="abuse@panix.com"
User-Agent: Vectrex rn 2.1 (beta)
X-Liz: It's actually happened, the entire Internet is a massive game of Redcode
X-Motto: "Erosion of rights never seems to reverse itself." -- kenny@panix
X-US-Congress: Moronic Fucks.
X-Attribution: EtB
XFrom: is a real address
Encrypted: double rot-13
 by: Eli the Bearded - Sun, 12 Sep 2021 21:49 UTC

In comp.unix.shell, Oğuz <oguzismailuysal@gmail.com> wrote:
> For example:
>
> f(1.20000) => 1.2
> f(100) => 100
> f(1.0234) => 1.0234
> f(123.00) => 123
>
> How would you implement such a function as f in bc?

Who's to say 1.2 is more accurate than 1.20000? If I see something
specified has 1.20000 meters, than I'll expect that it is not 1.20010
meters. If I see something specified as 1.2 meters, than 1.20010 is very
much within spec.

For your example of "just drop zeros at the end of a decimal sequence",
I'd do that in sed or something.

sed -e 's/\([(.][0-9]*[1-9]\)0*$/\1/; s/[.]0*$//'

Elijah
------
but maybe you want to keep the decimal place, eg 1.0000 => 1.

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<shm2tq$bia$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4347&group=comp.unix.shell#4347

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: dan1es...@gmail.com (Dan Espen)
Newsgroups: comp.unix.shell
Subject: Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc
Date: Sun, 12 Sep 2021 19:36:26 -0400
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <shm2tq$bia$1@dont-email.me>
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
<eli$2109121749@qaz.wtf>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="d978879738e14f8ab2625aaf10de14c6";
logging-data="11850"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18CXt9YIH1h4cm+MvQT0BrsHYoX3K/rc+M="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:ZHY2ghr1M2pGpjZsYnVAD3Oxzdo=
 by: Dan Espen - Sun, 12 Sep 2021 23:36 UTC

Eli the Bearded <*@eli.users.panix.com> writes:

> In comp.unix.shell, Oğuz <oguzismailuysal@gmail.com> wrote:
>> For example:
>>
>> f(1.20000) => 1.2
>> f(100) => 100
>> f(1.0234) => 1.0234
>> f(123.00) => 123
>>
>> How would you implement such a function as f in bc?
>
> Who's to say 1.2 is more accurate than 1.20000? If I see something
> specified has 1.20000 meters, than I'll expect that it is not 1.20010
> meters. If I see something specified as 1.2 meters, than 1.20010 is very
> much within spec.

I have to agree, the number of decimals can be an indication of
accuracy. I use bc a lot and for what I'm doing, I always want 2
decimals.

In my ~/.bc file I have:

scale=2

--
Dan Espen

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<8735q9gtc5.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4349&group=comp.unix.shell#4349

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc
Date: Mon, 13 Sep 2021 02:25:14 +0100
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <8735q9gtc5.fsf@bsb.me.uk>
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
<eli$2109121749@qaz.wtf> <shm2tq$bia$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="3157720ab16954c609b87c402848edeb";
logging-data="3845"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+xqdoFLdk+LHWAKGpLV/Lgapm/lktDSBQ="
Cancel-Lock: sha1:lJmX03qp4FNGAzy3NlR8ZHnHRy4=
sha1:Y9Tr6H7/lUDOnt8ar4ssNt6rA6I=
X-BSB-Auth: 1.1356d40a8e7d3d1632c0.20210913022514BST.8735q9gtc5.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 13 Sep 2021 01:25 UTC

Dan Espen <dan1espen@gmail.com> writes:

> Eli the Bearded <*@eli.users.panix.com> writes:

>> Who's to say 1.2 is more accurate than 1.20000? If I see something
>> specified has 1.20000 meters, than I'll expect that it is not 1.20010
>> meters. If I see something specified as 1.2 meters, than 1.20010 is very
>> much within spec.
>
> I have to agree, the number of decimals can be an indication of
> accuracy. I use bc a lot and for what I'm doing, I always want 2
> decimals.
>
> In my ~/.bc file I have:
>
> scale=2

That may do what you want, but I think it's worth pointing out for a
wider audience that bc does not round into the last digit, but truncates
to it. Also, the setting is not a display option for numbers stored
internally with greater precision, but governs the precision used for
some arithmetic results. For example

scale=2; 1.0099+0; 1.0099*1; 1.0099/1

produces

1.0099
1.0099
1.00

which is unlikely to be what anyone wants!

--
Ben.

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<de7d712c-fe7e-4030-b34e-884e6d7a8e3fn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4351&group=comp.unix.shell#4351

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ad4:5630:: with SMTP id cb16mr8517198qvb.45.1631503958507;
Sun, 12 Sep 2021 20:32:38 -0700 (PDT)
X-Received: by 2002:a05:620a:13cb:: with SMTP id g11mr8034462qkl.332.1631503958333;
Sun, 12 Sep 2021 20:32:38 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sun, 12 Sep 2021 20:32:38 -0700 (PDT)
In-Reply-To: <eli$2109121749@qaz.wtf>
Injection-Info: google-groups.googlegroups.com; posting-host=85.103.121.52; posting-account=RbOzpwoAAACSDI6OO1wVarfPakNstxUl
NNTP-Posting-Host: 85.103.121.52
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com> <eli$2109121749@qaz.wtf>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <de7d712c-fe7e-4030-b34e-884e6d7a8e3fn@googlegroups.com>
Subject: Re: Removing non-significant zeros from the fractional portion of a
number in POSIX bc
From: oguzisma...@gmail.com (Oğuz)
Injection-Date: Mon, 13 Sep 2021 03:32:38 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Oğuz - Mon, 13 Sep 2021 03:32 UTC

On Monday, September 13, 2021 at 12:49:27 AM UTC+3, Eli the Bearded wrote:
> In comp.unix.shell, Oğuz <oguzism...@gmail.com> wrote:
> > For example:
> >
> > f(1.20000) => 1.2
> > f(100) => 100
> > f(1.0234) => 1.0234
> > f(123.00) => 123
> >
> > How would you implement such a function as f in bc?
> Who's to say 1.2 is more accurate than 1.20000? If I see something
> specified has 1.20000 meters, than I'll expect that it is not 1.20010
> meters. If I see something specified as 1.2 meters, than 1.20010 is very
> much within spec.

I didn't think about this. Sigh, now it's got more complicated.

Say, you're converting 1.323 days to seconds, wouldn't you expect the result to be 114307.2 seconds? Wouldn't the trailing zeros in 114307.200 be redundant?

For context, I'm writing a shell script that accepts inputs like ``1d2h3m4.5s'' (one day, two hours, three minutes, and four point five seconds) and converts them to seconds for internal computations; and the user may request that the result of this conversion be printed immediately. Right now it doesn't allow a decimal point in days, hours, and minutes fields; but I've been considering allowing such inputs as ``1.323d'' (one point three twenty-three days) after I figure out how they should look after conversion.

>
> For your example of "just drop zeros at the end of a decimal sequence",
> I'd do that in sed or something.
>
> sed -e 's/\([(.][0-9]*[1-9]\)0*$/\1/; s/[.]0*$//'
>
> Elijah
> ------
> but maybe you want to keep the decimal place, eg 1.0000 => 1.

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<87bl4xdnq0.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4352&group=comp.unix.shell#4352

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc
Date: Sun, 12 Sep 2021 22:54:47 -0700
Organization: None to speak of
Lines: 57
Message-ID: <87bl4xdnq0.fsf@nosuchdomain.example.com>
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
<eli$2109121749@qaz.wtf>
<de7d712c-fe7e-4030-b34e-884e6d7a8e3fn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="e83d81b25f2da6d9984af3eca4a24311";
logging-data="15227"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+NBJytHMbnD4GHDo4rzcZ1"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:j6UpvG2Iqmd2o4e9fkjFQT4+06I=
sha1:oXIbSdOy0GO/GJshj9LVmywaAWg=
 by: Keith Thompson - Mon, 13 Sep 2021 05:54 UTC

Oğuz <oguzismailuysal@gmail.com> writes:
> On Monday, September 13, 2021 at 12:49:27 AM UTC+3, Eli the Bearded wrote:
>> In comp.unix.shell, Oğuz <oguzism...@gmail.com> wrote:
>> > For example:
>> >
>> > f(1.20000) => 1.2
>> > f(100) => 100
>> > f(1.0234) => 1.0234
>> > f(123.00) => 123
>> >
>> > How would you implement such a function as f in bc?
>> Who's to say 1.2 is more accurate than 1.20000? If I see something
>> specified has 1.20000 meters, than I'll expect that it is not 1.20010
>> meters. If I see something specified as 1.2 meters, than 1.20010 is very
>> much within spec.
>
> I didn't think about this. Sigh, now it's got more complicated.

You didn't initially say that you wanted the result to express a
meaningful precision.

> Say, you're converting 1.323 days to seconds, wouldn't you expect the
> result to be 114307.2 seconds? Wouldn't the trailing zeros in
> 114307.200 be redundant?
>
> For context, I'm writing a shell script that accepts inputs like
> ``1d2h3m4.5s'' (one day, two hours, three minutes, and four point five
> seconds) and converts them to seconds for internal computations; and
> the user may request that the result of this conversion be printed
> immediately. Right now it doesn't allow a decimal point in days,
> hours, and minutes fields; but I've been considering allowing such
> inputs as ``1.323d'' (one point three twenty-three days) after I
> figure out how they should look after conversion.

One approach that might make sense is to allow a non-integer value only
for the last field, so that for example "1.5d" is allowed by "1.5d1h" is
not.

Or you could allow real values for all fields, but I wouldn't expect
that to be used very often.

If your goal is to produce a number of seconds with a sensible number of
decimal places based on the input, you could consider each field to
specify a precision. A field of "1.323d" would specify a precision of
0.001 day (86.4 seconds). Whichever field specifies the greatest
precision could control the precision of the result. For example,
"3.1415926535d" would represent a precision of 8.64 microseconds, so the
result might be expressed as 271433.60526 seconds (if I've calculated it
correctly).

But consider whether users are going to expect "3.14d" and "3.140d" to
have different meanings.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<shn59f$uj2$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4353&group=comp.unix.shell#4353

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!k03buBvHr7vkGaN2ImDPQQ.user.46.165.242.75.POSTED!not-for-mail
From: anw...@cuboid.co.uk (Andy Walker)
Newsgroups: comp.unix.shell
Subject: Re: Removing non-significant zeros from the fractional portion of a
number in POSIX bc
Date: Mon, 13 Sep 2021 10:22:55 +0100
Organization: Not very much
Message-ID: <shn59f$uj2$1@gioia.aioe.org>
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
<eli$2109121749@qaz.wtf>
<de7d712c-fe7e-4030-b34e-884e6d7a8e3fn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="31330"; posting-host="k03buBvHr7vkGaN2ImDPQQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-GB
 by: Andy Walker - Mon, 13 Sep 2021 09:22 UTC

On 13/09/2021 04:32, Oğuz wrote:
>[...] Sigh, now it's got more complicated.
> Say, you're converting 1.323 days to seconds, wouldn't you expect the
> result to be 114307.2 seconds? Wouldn't the trailing zeros in
> 114307.200 be redundant?
> For context, I'm writing a shell script that accepts inputs like
> ``1d2h3m4.5s'' [...].

I think the answer is probably to use interval arithmetic,
of which this is a fairly simple example as you're [presumably] not
multiplying times together [to get square hours, or whatever!] nor
dividing them. So "1.323d" means "between 1.3225 and 1.3235 days"
"1d2h3m4.5s" means "between 1d2h3m4.45s and 1d2h3m4.55s" and
"1.2d 3.4h" means "between 1.15d 3.35h and 1.25d 3.45h". Convert
to seconds, or microseconds, or whatever, and, when printing,
print the lower and upper times as far as they agree; anything
after that is "noise". Details left as an exercise.

Note that for your "1.323d" example, the upper and lower
times differ by over a minute, so no, it shouldn't be printed out
with even one decimal place of seconds. For that, the user should
perhaps have specified "1.323000d".

[Interval arithmetic is commonly implemented in symbolic
algebra packages; whether it's available in any standard shell
commands or facilities, I don't know and haven't investigated.]

--
Andy Walker, Nottingham.
Andy's music pages: www.cuboid.me.uk/andy/Music
Composer of the day: www.cuboid.me.uk/andy/Music/Composers/Goodban

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<514a95e1-97bd-4ca6-8094-64402ac3c962n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4354&group=comp.unix.shell#4354

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a0c:d412:: with SMTP id t18mr10570198qvh.53.1631537530772;
Mon, 13 Sep 2021 05:52:10 -0700 (PDT)
X-Received: by 2002:a05:622a:1452:: with SMTP id v18mr9433983qtx.214.1631537530492;
Mon, 13 Sep 2021 05:52:10 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Mon, 13 Sep 2021 05:52:10 -0700 (PDT)
In-Reply-To: <shn59f$uj2$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=85.103.121.52; posting-account=RbOzpwoAAACSDI6OO1wVarfPakNstxUl
NNTP-Posting-Host: 85.103.121.52
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
<eli$2109121749@qaz.wtf> <de7d712c-fe7e-4030-b34e-884e6d7a8e3fn@googlegroups.com>
<shn59f$uj2$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <514a95e1-97bd-4ca6-8094-64402ac3c962n@googlegroups.com>
Subject: Re: Removing non-significant zeros from the fractional portion of a
number in POSIX bc
From: oguzisma...@gmail.com (Oğuz)
Injection-Date: Mon, 13 Sep 2021 12:52:10 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 41
 by: Oğuz - Mon, 13 Sep 2021 12:52 UTC

On Monday, September 13, 2021 at 12:23:04 PM UTC+3, Andy Walker wrote:
> On 13/09/2021 04:32, Oğuz wrote:
> >[...] Sigh, now it's got more complicated.
> > Say, you're converting 1.323 days to seconds, wouldn't you expect the
> > result to be 114307.2 seconds? Wouldn't the trailing zeros in
> > 114307.200 be redundant?
> > For context, I'm writing a shell script that accepts inputs like
> > ``1d2h3m4.5s'' [...].
>
> I think the answer is probably to use interval arithmetic,
> of which this is a fairly simple example as you're [presumably] not
> multiplying times together [to get square hours, or whatever!] nor
> dividing them. So "1.323d" means "between 1.3225 and 1.3235 days"
> "1d2h3m4.5s" means "between 1d2h3m4.45s and 1d2h3m4.55s" and
> "1.2d 3.4h" means "between 1.15d 3.35h and 1.25d 3.45h". Convert
> to seconds, or microseconds, or whatever, and, when printing,
> print the lower and upper times as far as they agree; anything
> after that is "noise". Details left as an exercise.

This is beyond me. Besides, the script uses an arbitrary precision calculator (bc) for all computations (and users are made aware of this, assuming they actually read the manual). So, ``1.323d'' does not represent a value between any two others; it is precisely 1.323 days, no distinction is made between 1.323 and 1.3230000000000000000000 in bc. That's why I thought removing trailing zeros from the fractional portion would suffice, but then Eli's message confused me.

>
> Note that for your "1.323d" example, the upper and lower
> times differ by over a minute, so no, it shouldn't be printed out
> with even one decimal place of seconds. For that, the user should
> perhaps have specified "1.323000d".
>
> [Interval arithmetic is commonly implemented in symbolic
> algebra packages; whether it's available in any standard shell
> commands or facilities, I don't know and haven't investigated.]
>
> --
> Andy Walker, Nottingham.
> Andy's music pages: www.cuboid.me.uk/andy/Music
> Composer of the day: www.cuboid.me.uk/andy/Music/Composers/Goodban

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<87tuiofwjs.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4355&group=comp.unix.shell#4355

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc
Date: Mon, 13 Sep 2021 14:13:27 +0100
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <87tuiofwjs.fsf@bsb.me.uk>
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
<eli$2109121749@qaz.wtf>
<de7d712c-fe7e-4030-b34e-884e6d7a8e3fn@googlegroups.com>
<shn59f$uj2$1@gioia.aioe.org>
<514a95e1-97bd-4ca6-8094-64402ac3c962n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="3157720ab16954c609b87c402848edeb";
logging-data="24621"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/vACy9SuSfI6j0zA4RJ8s0IHihESK43r4="
Cancel-Lock: sha1:rsg7y5cnd1fVYQe3dZ4bhXPqXvw=
sha1:pfHaCiAFVhNFO/cZ1wAVlNCMFD4=
X-BSB-Auth: 1.741db721e0862deafc65.20210913141327BST.87tuiofwjs.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 13 Sep 2021 13:13 UTC

Oğuz <oguzismailuysal@gmail.com> writes:

> On Monday, September 13, 2021 at 12:23:04 PM UTC+3, Andy Walker wrote:
>> On 13/09/2021 04:32, Oğuz wrote:
>> >[...] Sigh, now it's got more complicated.
>> > Say, you're converting 1.323 days to seconds, wouldn't you expect the
>> > result to be 114307.2 seconds? Wouldn't the trailing zeros in
>> > 114307.200 be redundant?
>> > For context, I'm writing a shell script that accepts inputs like
>> > ``1d2h3m4.5s'' [...].
>>
>> I think the answer is probably to use interval arithmetic,
>> of which this is a fairly simple example as you're [presumably] not
>> multiplying times together [to get square hours, or whatever!] nor
>> dividing them. So "1.323d" means "between 1.3225 and 1.3235 days"
>> "1d2h3m4.5s" means "between 1d2h3m4.45s and 1d2h3m4.55s" and
>> "1.2d 3.4h" means "between 1.15d 3.35h and 1.25d 3.45h". Convert
>> to seconds, or microseconds, or whatever, and, when printing,
>> print the lower and upper times as far as they agree; anything
>> after that is "noise". Details left as an exercise.
>
> This is beyond me. Besides, the script uses an arbitrary precision
> calculator (bc) for all computations (and users are made aware of
> this, assuming they actually read the manual). So, ``1.323d'' does not
> represent a value between any two others; it is precisely 1.323 days,
> no distinction is made between 1.323 and 1.3230000000000000000000 in
> bc. That's why I thought removing trailing zeros from the fractional
> portion would suffice, but then Eli's message confused me.

It's not common to interpret decimal fractions as representing exact
quantities because this privilege some values over others. If instead
of 1.323 days the user had wanted one and a third days, there is no
simple way to write that as a decimal fraction. (Well there is: 1.(3)
but it's no widely used in computing.)

The simplest way to do exact arithmetic is as fractions. 1.323 is
exactly 1323/1000 and all the other numbers can be similarly converted.
After adjusting to get a common divisor, you can then do all the
arithmetic as integers and divide once at the end. You need to do it
this way because of what bc does with division. You will then also know
how may digits to show after the point.

But it's unlikely that this is worth the effort. Is there significant
demand from users to see fewer zeros?

--
Ben.

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<shnlie$rul$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4356&group=comp.unix.shell#4356

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.shell
Subject: Re: Removing non-significant zeros from the fractional portion of a
number in POSIX bc
Date: Mon, 13 Sep 2021 14:00:46 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <shnlie$rul$1@dont-email.me>
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
<eli$2109121749@qaz.wtf>
<de7d712c-fe7e-4030-b34e-884e6d7a8e3fn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 13 Sep 2021 14:00:46 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="180145b779110f1ecda3f2c650d2464b";
logging-data="28629"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/wPcGx9YdfHf2NGUSVkRmcY4kB7DkDGtY="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:5EIWWDVckdKm53ktgP749J6zmfw=
 by: Lew Pitcher - Mon, 13 Sep 2021 14:00 UTC

On Sun, 12 Sep 2021 20:32:38 -0700, Oğuz wrote:

> On Monday, September 13, 2021 at 12:49:27 AM UTC+3, Eli the Bearded wrote:
>> In comp.unix.shell, Oğuz <oguzism...@gmail.com> wrote:
>> > For example:
>> >
>> > f(1.20000) => 1.2
>> > f(100) => 100
>> > f(1.0234) => 1.0234
>> > f(123.00) => 123
>> >
>> > How would you implement such a function as f in bc?
>> Who's to say 1.2 is more accurate than 1.20000? If I see something
>> specified has 1.20000 meters, than I'll expect that it is not 1.20010
>> meters. If I see something specified as 1.2 meters, than 1.20010 is very
>> much within spec.
>
> I didn't think about this. Sigh, now it's got more complicated.
>
> Say, you're converting 1.323 days to seconds, wouldn't you expect
> the result to be 114307.2 seconds? Wouldn't the trailing zeros in
> 114307.200 be redundant?

Instead of concentrating on the insignificant trailing zeros in your
converted values, you probably should be concentrating on ensuring
that the conversion maintains the accuracy of the values being
converted.

Both 114307.2 and 114307.200 represent the same value. The discussion
regarding a preference of one expression of that value ("114307.2")
over another ("114307.200") tells me that we aren't talking about
accuracy here, but /significance/. And that is a common quandary
among scientists and engineers; so much so that they've expressed
various recommendations regarding "significant numbers".

Your original value was 1.323 days. Likely, this number wasn't meant
to represent /exactly/ 114307.2 seconds, but instead was meant to
represent some interval of at least 1.3230 days, and no more than
1.3240 days. That interval represents approximately 86.4 seconds.

So, your example of 1.323 days likely represents a value somewhere
between 114307.2 and 114393.6 seconds. And, that's if we take your
1.323 as a completely accurate value.

But wait, there's more :-)

To quote one of the many articles on "significant digits",
"The significant figures in a measurement consist of all the
certain digits in that measurement plus one uncertain or
estimated digit."
(https://chem.libretexts.org/Bookshelves/Introductory_Chemistry/Map%3A_Introductory_Chemistry_(Tro)/02%3A_Measurement_and_Problem_Solving/2.03%3A_Significant_Figures_-_Writing_Numbers_to_Reflect_Precision)

If we work with this guideline, your figure of 1.323 could
represent a value of 1.32 days with an uncertainty of 0.003
days. So, somewhere between (approximately) 1.3225 days and
1.3235 days, or between 114264 seconds and 114350.4 seconds.

I know that computers work (mostly) with precise numbers, BUT
your conversion between time measurements isn't as precise
as the computer's computation will be.

HTH

[snip]
--
Lew Pitcher
"In Skills, We Trust"

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<8011820e-3f91-485c-9b1b-dfef46ce7fe0n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4357&group=comp.unix.shell#4357

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ac8:7309:: with SMTP id x9mr255382qto.162.1631547979406;
Mon, 13 Sep 2021 08:46:19 -0700 (PDT)
X-Received: by 2002:a37:ab12:: with SMTP id u18mr241500qke.516.1631547979028;
Mon, 13 Sep 2021 08:46:19 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Mon, 13 Sep 2021 08:46:18 -0700 (PDT)
In-Reply-To: <87tuiofwjs.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=178.247.103.67; posting-account=RbOzpwoAAACSDI6OO1wVarfPakNstxUl
NNTP-Posting-Host: 178.247.103.67
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
<eli$2109121749@qaz.wtf> <de7d712c-fe7e-4030-b34e-884e6d7a8e3fn@googlegroups.com>
<shn59f$uj2$1@gioia.aioe.org> <514a95e1-97bd-4ca6-8094-64402ac3c962n@googlegroups.com>
<87tuiofwjs.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8011820e-3f91-485c-9b1b-dfef46ce7fe0n@googlegroups.com>
Subject: Re: Removing non-significant zeros from the fractional portion of a
number in POSIX bc
From: oguzisma...@gmail.com (Oğuz)
Injection-Date: Mon, 13 Sep 2021 15:46:19 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 58
 by: Oğuz - Mon, 13 Sep 2021 15:46 UTC

On Monday, September 13, 2021 at 4:13:32 PM UTC+3, Ben Bacarisse wrote:
> Oğuz <oguzism...@gmail.com> writes:
>
> > On Monday, September 13, 2021 at 12:23:04 PM UTC+3, Andy Walker wrote:
> >> On 13/09/2021 04:32, Oğuz wrote:
> >> >[...] Sigh, now it's got more complicated.
> >> > Say, you're converting 1.323 days to seconds, wouldn't you expect the
> >> > result to be 114307.2 seconds? Wouldn't the trailing zeros in
> >> > 114307.200 be redundant?
> >> > For context, I'm writing a shell script that accepts inputs like
> >> > ``1d2h3m4.5s'' [...].
> >>
> >> I think the answer is probably to use interval arithmetic,
> >> of which this is a fairly simple example as you're [presumably] not
> >> multiplying times together [to get square hours, or whatever!] nor
> >> dividing them. So "1.323d" means "between 1.3225 and 1.3235 days"
> >> "1d2h3m4.5s" means "between 1d2h3m4.45s and 1d2h3m4.55s" and
> >> "1.2d 3.4h" means "between 1.15d 3.35h and 1.25d 3.45h". Convert
> >> to seconds, or microseconds, or whatever, and, when printing,
> >> print the lower and upper times as far as they agree; anything
> >> after that is "noise". Details left as an exercise.
> >
> > This is beyond me. Besides, the script uses an arbitrary precision
> > calculator (bc) for all computations (and users are made aware of
> > this, assuming they actually read the manual). So, ``1.323d'' does not
> > represent a value between any two others; it is precisely 1.323 days,
> > no distinction is made between 1.323 and 1.3230000000000000000000 in
> > bc. That's why I thought removing trailing zeros from the fractional
> > portion would suffice, but then Eli's message confused me.
> It's not common to interpret decimal fractions as representing exact
> quantities because this privilege some values over others. If instead
> of 1.323 days the user had wanted one and a third days, there is no
> simple way to write that as a decimal fraction. (Well there is: 1.(3)
> but it's no widely used in computing.)

In that case the user would enter ``1d8h''. I got the point though.

>
> The simplest way to do exact arithmetic is as fractions. 1.323 is
> exactly 1323/1000 and all the other numbers can be similarly converted.
> After adjusting to get a common divisor, you can then do all the
> arithmetic as integers and divide once at the end. You need to do it
> this way because of what bc does with division. You will then also know
> how may digits to show after the point.
>
> But it's unlikely that this is worth the effort. Is there significant
> demand from users to see fewer zeros?

Oh, none yet. No demand. I thought it'd be useful, that's all.

>
> --
> Ben.

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<3c0c2f84-3ba7-4153-9c2f-7f67ab9be822n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4358&group=comp.unix.shell#4358

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ae9:e502:: with SMTP id w2mr278646qkf.200.1631548148809;
Mon, 13 Sep 2021 08:49:08 -0700 (PDT)
X-Received: by 2002:a05:620a:1009:: with SMTP id z9mr215795qkj.483.1631548148660;
Mon, 13 Sep 2021 08:49:08 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Mon, 13 Sep 2021 08:49:08 -0700 (PDT)
In-Reply-To: <shnlie$rul$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=178.247.103.67; posting-account=RbOzpwoAAACSDI6OO1wVarfPakNstxUl
NNTP-Posting-Host: 178.247.103.67
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
<eli$2109121749@qaz.wtf> <de7d712c-fe7e-4030-b34e-884e6d7a8e3fn@googlegroups.com>
<shnlie$rul$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3c0c2f84-3ba7-4153-9c2f-7f67ab9be822n@googlegroups.com>
Subject: Re: Removing non-significant zeros from the fractional portion of a
number in POSIX bc
From: oguzisma...@gmail.com (Oğuz)
Injection-Date: Mon, 13 Sep 2021 15:49:08 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 77
 by: Oğuz - Mon, 13 Sep 2021 15:49 UTC

On Monday, September 13, 2021 at 5:00:52 PM UTC+3, Lew Pitcher wrote:
> On Sun, 12 Sep 2021 20:32:38 -0700, Oğuz wrote:
>
> > On Monday, September 13, 2021 at 12:49:27 AM UTC+3, Eli the Bearded wrote:
> >> In comp.unix.shell, Oğuz <oguzism...@gmail.com> wrote:
> >> > For example:
> >> >
> >> > f(1.20000) => 1.2
> >> > f(100) => 100
> >> > f(1.0234) => 1.0234
> >> > f(123.00) => 123
> >> >
> >> > How would you implement such a function as f in bc?
> >> Who's to say 1.2 is more accurate than 1.20000? If I see something
> >> specified has 1.20000 meters, than I'll expect that it is not 1.20010
> >> meters. If I see something specified as 1.2 meters, than 1.20010 is very
> >> much within spec.
> >
> > I didn't think about this. Sigh, now it's got more complicated.
> >
> > Say, you're converting 1.323 days to seconds, wouldn't you expect
> > the result to be 114307.2 seconds? Wouldn't the trailing zeros in
> > 114307.200 be redundant?
> Instead of concentrating on the insignificant trailing zeros in your
> converted values, you probably should be concentrating on ensuring
> that the conversion maintains the accuracy of the values being
> converted.
>
> Both 114307.2 and 114307.200 represent the same value. The discussion
> regarding a preference of one expression of that value ("114307.2")
> over another ("114307.200") tells me that we aren't talking about
> accuracy here, but /significance/. And that is a common quandary
> among scientists and engineers; so much so that they've expressed
> various recommendations regarding "significant numbers".
>
> Your original value was 1.323 days. Likely, this number wasn't meant
> to represent /exactly/ 114307.2 seconds, but instead was meant to
> represent some interval of at least 1.3230 days, and no more than
> 1.3240 days. That interval represents approximately 86.4 seconds.
>
> So, your example of 1.323 days likely represents a value somewhere
> between 114307.2 and 114393.6 seconds. And, that's if we take your
> 1.323 as a completely accurate value.
>
> But wait, there's more :-)
>
> To quote one of the many articles on "significant digits",
> "The significant figures in a measurement consist of all the
> certain digits in that measurement plus one uncertain or
> estimated digit."
> (https://chem.libretexts.org/Bookshelves/Introductory_Chemistry/Map%3A_Introductory_Chemistry_(Tro)/02%3A_Measurement_and_Problem_Solving/2.03%3A_Significant_Figures_-_Writing_Numbers_to_Reflect_Precision)

I'll read this when I have time, thank you.

>
> If we work with this guideline, your figure of 1.323 could
> represent a value of 1.32 days with an uncertainty of 0.003
> days. So, somewhere between (approximately) 1.3225 days and
> 1.3235 days, or between 114264 seconds and 114350.4 seconds.
>
> I know that computers work (mostly) with precise numbers, BUT
> your conversion between time measurements isn't as precise
> as the computer's computation will be.

Sounds like a good excuse to put this feature on hold :D

>
> HTH
>
> [snip]
> --
> Lew Pitcher
> "In Skills, We Trust"

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<shogu0$519$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4359&group=comp.unix.shell#4359

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chr...@mshome.net (Chris Elvidge)
Newsgroups: comp.unix.shell
Subject: Re: Removing non-significant zeros from the fractional portion of a
number in POSIX bc
Date: Mon, 13 Sep 2021 22:47:35 +0100
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <shogu0$519$1@dont-email.me>
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 13 Sep 2021 21:47:48 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="451f87257f055da6f88ff60c2e11cffd";
logging-data="5161"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19dK5LCROv0FvlY5ZJBcEIQafYG+m4qsug="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
Thunderbird/52.2.1 Lightning/5.4
Cancel-Lock: sha1:VcAHqrf0SaGVikL5u57xg2oWzB0=
In-Reply-To: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
Content-Language: en-GB
 by: Chris Elvidge - Mon, 13 Sep 2021 21:47 UTC

On 12/09/2021 07:39 pm, Oğuz wrote:
> For example:
>
> f(1.20000) => 1.2
> f(100) => 100
> f(1.0234) => 1.0234
> f(123.00) => 123
>
> How would you implement such a function as f in bc?
>

I wouldn't use bc, just bash.

rmz ()
{ local N;
# an integer, just return value
[[ $1 == ?([-+])+([0-9]) ]] && {
echo "$1";
return
};
N="$1";
# remove trailing 0, one by one
until [ "$N" = "${N%0}" ]; do
N="${N%0}";
done;
# remove any trailing .
echo "${N%.}"
}

If you set extglob (shopt -s extglob) you could substitute the until
loop with N="${N%%+(0)}"

--
Chris Elvidge
England

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<613fd396$0$507$65785112@news.neostrada.pl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4360&group=comp.unix.shell#4360

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-01.news.neostrada.pl!unt-spo-a-02.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
Subject: Re: Removing non-significant zeros from the fractional portion of a
number in POSIX bc
Newsgroups: comp.unix.shell
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
From: marr...@address.invalid (marrgol)
Date: Tue, 14 Sep 2021 00:41:26 +0200
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
MIME-Version: 1.0
In-Reply-To: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-GB
Content-Transfer-Encoding: 8bit
Lines: 27
Message-ID: <613fd396$0$507$65785112@news.neostrada.pl>
Organization: Telekomunikacja Polska
NNTP-Posting-Host: 176.111.237.144
X-Trace: 1631572886 unt-rea-b-01.news.neostrada.pl 507 176.111.237.144:54390
X-Complaints-To: abuse@news.neostrada.pl
X-Received-Bytes: 1491
 by: marrgol - Mon, 13 Sep 2021 22:41 UTC

On 12/09/2021 at 20.39, Oğuz wrote:
> For example:
>
> f(1.20000) => 1.2
> f(100) => 100
> f(1.0234) => 1.0234
> f(123.00) => 123
>
> How would you implement such a function as f in bc?

Consider using 'calc' instead of 'bc' for your calculations…

~ $ calc 1.20000
1.2
~ $ calc 100
100
~ $ calc 1.0234
1.0234
~ $ calc 123.00
123
~ $ calc 1.323*60*60*24
114307.2
~ $

--
mrg

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<eli$2109131939@qaz.wtf>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4362&group=comp.unix.shell#4362

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix5.panix.com!qz!not-for-mail
From: *...@eli.users.panix.com (Eli the Bearded)
Newsgroups: comp.unix.shell
Subject: Re: Removing non-significant zeros from the fractional portion of a
number in POSIX bc
Date: Mon, 13 Sep 2021 23:40:45 -0000 (UTC)
Organization: Some absurd concept
Message-ID: <eli$2109131939@qaz.wtf>
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com> <613fd396$0$507$65785112@news.neostrada.pl>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Mon, 13 Sep 2021 23:40:45 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="panix5.panix.com:166.84.1.5";
logging-data="23525"; mail-complaints-to="abuse@panix.com"
User-Agent: Vectrex rn 2.1 (beta)
X-Liz: It's actually happened, the entire Internet is a massive game of Redcode
X-Motto: "Erosion of rights never seems to reverse itself." -- kenny@panix
X-US-Congress: Moronic Fucks.
X-Attribution: EtB
XFrom: is a real address
Encrypted: double rot-13
 by: Eli the Bearded - Mon, 13 Sep 2021 23:40 UTC

In comp.unix.shell, marrgol <marrgol@address.invalid> wrote:
> Consider using 'calc' instead of 'bc' for your calculations…

Ubuntu 18.04.5: command not found
NetBSD 9.1: command not found

If you're not going to provide any more information about the program
than the name, and the post says POSIX in the subject, then shouldn't
you only be mentioning programs that are pretty standardized?

Elijah
------
knows people that could whip up an Excel formula for this but...

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<shosnk$76e$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4363&group=comp.unix.shell#4363

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: dan1es...@gmail.com (Dan Espen)
Newsgroups: comp.unix.shell
Subject: Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc
Date: Mon, 13 Sep 2021 21:09:08 -0400
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <shosnk$76e$1@dont-email.me>
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
<613fd396$0$507$65785112@news.neostrada.pl> <eli$2109131939@qaz.wtf>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="b54b1791bba3610c1895b5df6b9f5c1e";
logging-data="7374"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+XT9FwTXrSXdiUmQGWnkT2/CV1TJyHgIw="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:H51faH+OEnLCg9+h8mvSLd2Pkic=
 by: Dan Espen - Tue, 14 Sep 2021 01:09 UTC

Eli the Bearded <*@eli.users.panix.com> writes:

> In comp.unix.shell, marrgol <marrgol@address.invalid> wrote:
>> Consider using 'calc' instead of 'bc' for your calculations…
>
> Ubuntu 18.04.5: command not found
> NetBSD 9.1: command not found
>
> If you're not going to provide any more information about the program
> than the name, and the post says POSIX in the subject, then shouldn't
> you only be mentioning programs that are pretty standardized?

Fedora not found...

sudo dnf install calc

> calc 4/7
~0.57142857142857142857

Hmm...

--
Dan Espen

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<eli$2109132129@qaz.wtf>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4364&group=comp.unix.shell#4364

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix5.panix.com!qz!not-for-mail
From: *...@eli.users.panix.com (Eli the Bearded)
Newsgroups: comp.unix.shell
Subject: Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc
Date: Tue, 14 Sep 2021 01:29:40 -0000 (UTC)
Organization: Some absurd concept
Message-ID: <eli$2109132129@qaz.wtf>
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com> <613fd396$0$507$65785112@news.neostrada.pl> <eli$2109131939@qaz.wtf> <shosnk$76e$1@dont-email.me>
Injection-Date: Tue, 14 Sep 2021 01:29:40 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="panix5.panix.com:166.84.1.5";
logging-data="23173"; mail-complaints-to="abuse@panix.com"
User-Agent: Vectrex rn 2.1 (beta)
X-Liz: It's actually happened, the entire Internet is a massive game of Redcode
X-Motto: "Erosion of rights never seems to reverse itself." -- kenny@panix
X-US-Congress: Moronic Fucks.
X-Attribution: EtB
XFrom: is a real address
Encrypted: double rot-13
 by: Eli the Bearded - Tue, 14 Sep 2021 01:29 UTC

In comp.unix.shell, Dan Espen <dan1espen@gmail.com> wrote:
> Fedora not found...
>
> sudo dnf install calc

There's no calc package on Ubuntu. apcalc provides a /usr/bin/calc
but I didn't try to install it, because: I have no idea if it's
the same tool, or just someone else using the same name. I mean it's
not like "calc" is an unlikely name for a calculator.

(I don't have root on this NetBSD system, so I didn't even consider
looking for a package.)

Elijah
------
would consider dc and bc to be somewhat unlikely names

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<877dfjewqh.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4365&group=comp.unix.shell#4365

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc
Date: Mon, 13 Sep 2021 19:07:02 -0700
Organization: None to speak of
Lines: 28
Message-ID: <877dfjewqh.fsf@nosuchdomain.example.com>
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
<613fd396$0$507$65785112@news.neostrada.pl> <eli$2109131939@qaz.wtf>
<shosnk$76e$1@dont-email.me> <eli$2109132129@qaz.wtf>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="e43aa629221922c685a4d1b5cdadf7b9";
logging-data="24578"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+1huTW1whiFbqPhEkzQ/PW"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:j5jbZvA53cL5+Ak1p6l/Id6dODI=
sha1:D7jd8J/TB3nCYegf8Gy7ayrDArk=
 by: Keith Thompson - Tue, 14 Sep 2021 02:07 UTC

Eli the Bearded <*@eli.users.panix.com> writes:
> In comp.unix.shell, Dan Espen <dan1espen@gmail.com> wrote:
>> Fedora not found...
>>
>> sudo dnf install calc
>
> There's no calc package on Ubuntu. apcalc provides a /usr/bin/calc
> but I didn't try to install it, because: I have no idea if it's
> the same tool, or just someone else using the same name. I mean it's
> not like "calc" is an unlikely name for a calculator.
>
> (I don't have root on this NetBSD system, so I didn't even consider
> looking for a package.)

There is an installable Debian and Ubuntu package named "calc". It's
not installed by default.

Previously, this package was named `apcalc' in Debian due to a name
collision. However, the previous `calc' Debian package vanished long ago,
so `apcalc' was renamed back to `calc' to match the upstream name.

Yes, it is a rather generic name (and I've just decided to rename my own
"calc" program because of this).

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<shpp1l$1pes$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4367&group=comp.unix.shell#4367

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!I4G2pI/TjSgw9iO3pv/WTg.user.46.165.242.75.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Removing non-significant zeros from the fractional portion of a
number in POSIX bc
Date: Tue, 14 Sep 2021 11:12:21 +0200
Organization: Aioe.org NNTP Server
Message-ID: <shpp1l$1pes$1@gioia.aioe.org>
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
<eli$2109121749@qaz.wtf>
<de7d712c-fe7e-4030-b34e-884e6d7a8e3fn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="58844"; posting-host="I4G2pI/TjSgw9iO3pv/WTg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Enigmail-Draft-Status: N1110
X-Notice: Filtered by postfilter v. 0.9.2
 by: Janis Papanagnou - Tue, 14 Sep 2021 09:12 UTC

On 13.09.2021 05:32, Oğuz wrote:
> [...]
>
> For context, I'm writing a shell script that accepts inputs like
> ``1d2h3m4.5s'' (one day, two hours, three minutes, and four point
> five seconds) and converts them to seconds for internal computations;
> and the user may request that the result of this conversion be
> printed immediately. Right now it doesn't allow a decimal point in
> days, hours, and minutes fields; but I've been considering allowing
> such inputs as ``1.323d'' (one point three twenty-three days) after I
> figure out how they should look after conversion.

Period to seconds conversions can quite easily be computed in shell.
Kornshell also allows fractional arithmetic which simplifies matters.

$ cat period
p=${1:?}
s=${p}
s=${s/[Dd]/*24*60*60+}
s=${s/[Hh]/*60*60+}
s=${s/[Mm]/*60+}
s=${s/[Ss]}
s=${s%+}
printf "%s\n" "${p}" "${s}" "$((s))"

$ ksh period 1d2h5.5m3.7s
1d2h5.5m3.7s
1*24*60*60+2*60*60+5.5*60+3.7
93933.7

We can see that all the components (no only the seconds) can also be
fractions, so that this requirement would also be covered.

(The question remains - not sure it matters in your context - how to
convert larger time entities, like 'year'; would 365.2425 days be ok?)

If you want to formalize the interface you may also want to consider
using the ISO time period syntax that starts with a 'P' and (IIRC) is
using all capitals, like in 'P1D10.33S'. (Just BTW.)

Janis

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<61407645$0$23913$65785112@news.neostrada.pl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4368&group=comp.unix.shell#4368

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!unt-spo-a-02.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
Subject: Re: Removing non-significant zeros from the fractional portion of a
number in POSIX bc
Newsgroups: comp.unix.shell
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
<613fd396$0$507$65785112@news.neostrada.pl> <eli$2109131939@qaz.wtf>
From: marr...@address.invalid (marrgol)
Date: Tue, 14 Sep 2021 12:15:33 +0200
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
MIME-Version: 1.0
In-Reply-To: <eli$2109131939@qaz.wtf>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-GB
Content-Transfer-Encoding: 8bit
Lines: 25
Message-ID: <61407645$0$23913$65785112@news.neostrada.pl>
Organization: Telekomunikacja Polska
NNTP-Posting-Host: 176.111.237.144
X-Trace: 1631614533 unt-rea-a-01.news.neostrada.pl 23913 176.111.237.144:54702
X-Complaints-To: abuse@news.neostrada.pl
X-Received-Bytes: 1987
 by: marrgol - Tue, 14 Sep 2021 10:15 UTC

On 14/09/2021 at 01.40, Eli the Bearded wrote:
>> Consider using 'calc' instead of 'bc' for your calculations…
>
> Ubuntu 18.04.5: command not found
> NetBSD 9.1: command not found
>
> If you're not going to provide any more information about the program
> than the name, and the post says POSIX in the subject, then shouldn't
> you only be mentioning programs that are pretty standardized?

Ah! Right! POSIX. Sorry. Keep forgetting about that POSIX zealotry…
Comes with age, I guess… I mean forgetting, not zealotry. ;-)

And for those who who might still be interested in calc but don't
know what to do with 'command not found' or are afraid to install
and try packages from the repos of their OS, or it's just not there,
here is the source:

http://www.isthe.com/chongo/tech/comp/calc/index.html

And look! It's older than POSIX! ;-)

--
mrg

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<614076a2$0$23913$65785112@news.neostrada.pl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4369&group=comp.unix.shell#4369

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.net!news2.arglkargh.de!news.in-chemnitz.de!3.eu.feeder.erje.net!feeder.erje.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!unt-spo-a-01.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
Subject: Re: Removing non-significant zeros from the fractional portion of a
number in POSIX bc
Newsgroups: comp.unix.shell
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
<613fd396$0$507$65785112@news.neostrada.pl> <eli$2109131939@qaz.wtf>
<shosnk$76e$1@dont-email.me>
From: marr...@address.invalid (marrgol)
Date: Tue, 14 Sep 2021 12:17:06 +0200
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
MIME-Version: 1.0
In-Reply-To: <shosnk$76e$1@dont-email.me>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: pl-PL
Content-Transfer-Encoding: 7bit
Lines: 12
Message-ID: <614076a2$0$23913$65785112@news.neostrada.pl>
Organization: Telekomunikacja Polska
NNTP-Posting-Host: 176.111.237.144
X-Trace: 1631614626 unt-rea-a-01.news.neostrada.pl 23913 176.111.237.144:54702
X-Complaints-To: abuse@news.neostrada.pl
 by: marrgol - Tue, 14 Sep 2021 10:17 UTC

On 14/09/2021 at 03.09, Dan Espen wrote:
>> calc 4/7
> ~0.57142857142857142857
>
> Hmm...

What's wrong about it? You did notice it's not 'minus' in front
of that number and you did read the man page?

--
mrg

Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc

<shq47v$kpg$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4370&group=comp.unix.shell#4370

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: dan1es...@gmail.com (Dan Espen)
Newsgroups: comp.unix.shell
Subject: Re: Removing non-significant zeros from the fractional portion of a number in POSIX bc
Date: Tue, 14 Sep 2021 08:23:27 -0400
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <shq47v$kpg$1@dont-email.me>
References: <85bc1260-0dfb-4c55-a821-a54347b5b129n@googlegroups.com>
<613fd396$0$507$65785112@news.neostrada.pl> <eli$2109131939@qaz.wtf>
<shosnk$76e$1@dont-email.me>
<614076a2$0$23913$65785112@news.neostrada.pl>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="b54b1791bba3610c1895b5df6b9f5c1e";
logging-data="21296"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+bo31Ja4v2FlcfW7MGbRLTTcobWy31FJc="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:v6daBi5YaDlYHaHysTlHjBP8tUI=
 by: Dan Espen - Tue, 14 Sep 2021 12:23 UTC

marrgol <marrgol@address.invalid> writes:

> On 14/09/2021 at 03.09, Dan Espen wrote:
>>> calc 4/7
>> ~0.57142857142857142857
>> Hmm...
>
> What's wrong about it? You did notice it's not 'minus' in front
> of that number and you did read the man page?

I haven't read the man page but for my use I don't want to see all those
decimal places, 2 will do me fine.

Without the man page I tried // instead of /. Gives me zero decimal
places and truncation. I see "calc help round" gives me something.
Guess this isn't a simple tool, I suppose I should read the man page...

--
Dan Espen

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor