Re: CURRENT: bc -e results in empty string/result

From: Hartmann, O. <o.hartmann_at_walstatt.org>
Date: Sat, 4 Jul 2020 11:50:31 +0200
On Fri, 3 Jul 2020 17:58:27 +0200
Stefan Eßer <se_at_freebsd.org> wrote:

> Am 03.07.20 um 17:24 schrieb O. Hartmann:
> > Hello list,
> > 
> > running some scripts caluclating via bc() the expression shown
> > below:
> > 
> > bc -e '6582031 - 1048576 - 0 - 409600 - 1024 - 40 - 4096' -e quit  
> 
> The bc in -CURRENT has been replaced by a new implementation.
> 
> It seems there is one deviation from the behavior of the "old"
> version, in that it executes the "quit" immediately after parsing it.
> 
> There is a difference between "quit" and "halt", and the following
> command works as expected:
> 
> $ bc -e '6582031 - 1048576 - 0 - 409600 - 1024 - 40 - 4096' -e halt
> 5118695
> 
> From the bc man-page:
> 
>  The quit statement causes bc(1) to quit, even if it is on a branch
> that will not be executed (it is a compile-time command).
> 
>  The halt statement causes bc(1) to quit, if it is executed. (Unlike
>  quit if it is on a branch of an if statement that is not executed,
>  bc(1) does not quit.)
> 
> This behavior is identical to that of GNU bc:
> 
> $ echo "6582031 - 1048576 - 0 - 409600 - 1024 - 40 - 4096; quit " |
> gbc $ echo "6582031 - 1048576 - 0 - 409600 - 1024 - 40 - 4096; halt "
> | gbc 5118695
> 
> > results on recent CURRENT ( FreeBSD 13.0-CURRENT #80 r362884: Thu
> > Jul  2 10:08:23 CEST 2020 amd64) with an empty result, while it is
> > calculated correctly on 12-STABLE (FreeBSD 12.1-STABLE #67 r362719:
> > Sun Jun 28 09:59:20 CEST 2020 amd64) and a CURRENT dated from  Sun
> > Jun 28th (have no revision number anymore, the expression above was
> > calculated correctly on the same box which now has r362884 and is
> > failing).
> > 
> > Whats wrong?  
> 
> The behavior of the "old" bc in FreeBSD was non-conformant in several
> details, the result of a modulo operation with negative operands was
> the most critical, in my opinion.
> 
> This is what POSIX says with regard to the "quit" command:
> 
>  The quit statement ( quit) shall stop execution of a bc program at
> the point where the statement occurs in the input, even if it occurs
> in a function definition, or in an if, for, or while statement.
> 
> But I'm not sure whether this covers the behavior of GNU bc and this
> new bc, since it does not say, that "quit" will be executed as soon
> as seen by the parser.
> 
> Regards, STefan


Hello.

Unfortunately, there was no remark in UPDATING and in the hurry I did
not find any traces of the change, so it hit me since several scripts
failed. As a workaround, it helped to replace "-e quit" by "-e halt",
although this might semantically also an unfortunate way to do.

Thanks very much for the fast response,

regards
Oliver

Received on Sat Jul 04 2020 - 07:50:44 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:24 UTC