zsh-workers
 help / color / mirror / code / Atom feed
* [BUG] POSIX arith: inf, nan should be variables
@ 2021-11-15 17:40 Martijn Dekker
  2021-11-16  9:06 ` Oliver Kiddle
  2021-11-16 12:55 ` Vincent Lefevre
  0 siblings, 2 replies; 3+ messages in thread
From: Martijn Dekker @ 2021-11-15 17:40 UTC (permalink / raw)
  To: Zsh hackers list

$ zsh --emulate sh -c 'inf=1; nan=2; echo $((inf)) $((nan))'
Inf NaN

Expected: 1 2

This is a POSIX compliance issue that ksh93 also has (I've just fixed in 
ksh 93u+m). I can see why this is needed for full floating point 
arithmetic support, but in POSIX sh, all case variants of inf and nan 
are perfectly legitimate variables that portable scripts should be able 
to use, including in arithmetic evaluation. Their recognition should be 
turned off for sh emulation, but not for ksh emulation as ksh93's native 
mode also supports floating point arithmetic.

So, what shell option to tie that to? That's a bit difficult. It needs 
to be an option that is on for sh, but off for ksh (or vice versa). A 
comparison of 'set -o' output between sh and ksh modes shows that the 
options are limited to the following:

bsdecho
ignorebraces
kshglob
kshoptionprint
localoptions
localtraps
octalzeroes
promptbang
sharehistory
singlelinezle

The only one of those that has anything to do with an arithmetic context 
is octalzeroes, so that one may be the least bad one to choose. The 
preliminary patch below does that.

Perhaps octalzeroes could be renamed to something like posixmath, so 
that it becomes legitimate to attach this and any other POSIX arithmetic 
quirks to this option without further crowding the shell option space.

Thoughts/opinions?

--- a/Src/math.c
+++ b/Src/math.c
@@ -863,7 +863,7 @@ zzlex(void)

  		p = ptr;
  		ptr = ie;
-		if (ie - p == 3) {
+		if (ie - p == 3 && !isset(OCTALZEROES)) {
  		    if ((p[0] == 'N' || p[0] == 'n') &&
  			(p[1] == 'A' || p[1] == 'a') &&
  			(p[2] == 'N' || p[2] == 'n')) {

-- 
||	modernish -- harness the shell
||	https://github.com/modernish/modernish
||
||	KornShell lives!
||	https://github.com/ksh93/ksh


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG] POSIX arith: inf, nan should be variables
  2021-11-15 17:40 [BUG] POSIX arith: inf, nan should be variables Martijn Dekker
@ 2021-11-16  9:06 ` Oliver Kiddle
  2021-11-16 12:55 ` Vincent Lefevre
  1 sibling, 0 replies; 3+ messages in thread
From: Oliver Kiddle @ 2021-11-16  9:06 UTC (permalink / raw)
  To: Martijn Dekker; +Cc: Zsh hackers list

Martijn Dekker wrote:
> $ zsh --emulate sh -c 'inf=1; nan=2; echo $((inf)) $((nan))'
> Inf NaN
>
> Expected: 1 2

> So, what shell option to tie that to? That's a bit difficult. It needs 

The closest comparable feature is the decision in params.c as to whether
it should setup other special variables that aren't in the standard.

That seems to only check something like !EMULATION(EMULATE_SH) rather
than an actual option. Much of that has to run before zsh has got as far
as sourcing dot files that might setup options so it likely never made
sense to create an option for it. Most uses of directly checking
emulation state seem to be in initialisation code.

I wouldn't rename an option for compatibility. And while OCTAL_ZEROES is
similar in controlling interpretation of numbers in math mode it differs
in that it enables a potentially problematic standard feature while
Inf/NaN are a zsh extension. So I wouldn't view preferences on them as
being intrinsically linked.

Oliver


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG] POSIX arith: inf, nan should be variables
  2021-11-15 17:40 [BUG] POSIX arith: inf, nan should be variables Martijn Dekker
  2021-11-16  9:06 ` Oliver Kiddle
@ 2021-11-16 12:55 ` Vincent Lefevre
  1 sibling, 0 replies; 3+ messages in thread
From: Vincent Lefevre @ 2021-11-16 12:55 UTC (permalink / raw)
  To: zsh-workers

On 2021-11-15 18:40:17 +0100, Martijn Dekker wrote:
> $ zsh --emulate sh -c 'inf=1; nan=2; echo $((inf)) $((nan))'
> Inf NaN
> 
> Expected: 1 2

FYI, this had already been discussed in April in this subthread:

  https://www.zsh.org/mla/workers/2021/msg00717.html

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-16 12:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15 17:40 [BUG] POSIX arith: inf, nan should be variables Martijn Dekker
2021-11-16  9:06 ` Oliver Kiddle
2021-11-16 12:55 ` Vincent Lefevre

Code repositories for project(s) associated with this inbox:

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).