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

Re: inf and nan in arithmetic expansions



Stephane Chazelas wrote:
>
> neither "inf." nor "inf" are understood in arithmetic
> expressions (and for "inf.", nor by other tools like awk, or
> even the builtin printf):

> It should be safe to change zsh so that inf. (and Inf. INF. NAN.
> nan., maybe also Infinity.) are recognised in arithmetic
> expression, as it's currently invalid, but that leaves the
> problem of "inf." not being recognised by other tools
> (awk/printf).

There was actually a patch posted back in workers/19597 to do this. I
don't know why it never got integrated other than that a certain
amount of integration work was perhaps required.

It might be possible to forward port that work from 4.1.1 to the current
release. Would that be welcomed or was the original patch rejected for
good reasons? Any idea of where we might crib some decent test cases for
IEEE 754 arithmetic from?

> The printf builtin understands the C99 hex with binary
> exponent on input (where strtod supports them), but not on
> output (%a, %A) and not in arithmetic expressions
>
> $ printf "%g\n" 0x1p4
> 16
> $ printf "%a\n" 16
> printf: %a: invalid directive

This was down to %a not having been portable to all systems in wide
use at the time zsh's printf was written: we rely on the underlying C
library printf. Adding an autoconf test would have been a lot more work
than the code change to support it. From a quick check of man pages,
this is perhaps not a problem anymore. Could we add it today without
bothering with autoconf magic?

Oliver



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