From: Vincent Lefevre <vincent@vinc17.net>
To: zsh-workers@zsh.org
Subject: Re: inf and nan in arithmetic expansions
Date: Tue, 27 Feb 2018 17:56:33 +0100 [thread overview]
Message-ID: <20180227165633.GC26037@cventin.lip.ens-lyon.fr> (raw)
In-Reply-To: <12828.1519745147@thecus.kiddle.eu>
On 2018-02-27 16:25:47 +0100, Oliver Kiddle wrote:
> Vincent Lefevre wrote:
> > > This is actually system specific. We generate whatever printf(3)
> > > generates. Try out Stephane's examples on Solaris and you get Inf and
> > > NaN instead. I think I prefer those forms. We can make the printf code
> > > detect them and hard code a consistent form so that we are consistent
> > > across platforms.
> >
> > What do you mean by "We generate whatever printf(3) generates."?
>
> Zsh calls printf(3) to do the work underneath. The following code:
> #include <stdio.h>
> int main() { printf("%g\n", 1e9999); }
> Will output "Inf" on Solaris and "inf" on Linux (for glibc at least).
> And the zsh printf builtin does likewise on each platform.
Solaris is broken. The ISO C99 and C11 standards say:
A double argument representing an infinity is converted in one of the
styles [-]inf or [-]infinity — which style is implementation-defined.
A double argument representing a NaN is converted in one of the styles
[-]nan or [-]nan(n-char-sequence) — which style, and the meaning of
any n-char-sequence, is implementation-defined. The F conversion
specifier produces INF, INFINITY, or NAN instead of inf, infinity, or
nan, respectively.
Thus for the above example, the correct outputs are "inf" and
"infinity".
> > On Debian/unstable:
> >
> > cventin% echo $((1e9999))
> > inf.
>
> That trailing . is unrelated. It is added to ensure floating point types
> remain floating point which is not applicable to Inf and NaN.
OK, so whatever printf(3) generates and a trailing ".".
--
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)
next prev parent reply other threads:[~2018-02-27 16:56 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-07 22:30 Stephane Chazelas
2018-02-07 23:25 ` Oliver Kiddle
2018-02-08 9:38 ` Peter Stephenson
2018-02-08 12:46 ` Daniel Shahaf
2018-02-08 14:22 ` Stephane Chazelas
2018-02-09 15:31 ` Daniel Shahaf
2018-02-09 21:09 ` Stephane Chazelas
2018-02-10 0:10 ` Bart Schaefer
2018-02-16 16:51 ` Oliver Kiddle
2018-02-17 0:38 ` Daniel Shahaf
2018-02-19 14:19 ` Stephane Chazelas
2018-02-27 13:02 ` Vincent Lefevre
2018-02-27 15:25 ` Oliver Kiddle
2018-02-27 16:56 ` Vincent Lefevre [this message]
2018-03-21 23:46 ` Oliver Kiddle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180227165633.GC26037@cventin.lip.ens-lyon.fr \
--to=vincent@vinc17.net \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public 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).