Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[BUG] POSIX arith: inf, nan should be variables



$ 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




Messages sorted by: Reverse Date, Date, Thread, Author