zsh-workers
 help / color / mirror / code / Atom feed
From: David Hughes <dwhughes@gmail.com>
To: zsh-workers@zsh.org
Subject: 'typeset -F' behaves unexpectedly for "-F 1" and "-F 0"
Date: Sun, 03 May 2015 19:21:09 +0000	[thread overview]
Message-ID: <CAOcd6hrtTa7WVerarsU9+ZTWxa5G0g8f9Z+PGKCfMWZ7JWT-UA@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1528 bytes --]

If I run "typeset -F 1 pi=3.14159", I receive a warning of an invalid base,
and the parameter is not initialised. However, the parameter appears to be
created, and thereafter has the expected rounding attribute:

$ typeset -F 1 pi=3.14159
typeset: invalid base (must be 2 to 36 inclusive): 1
$ echo $pi
0.0
$ pi=2.71828
$ echo $pi
2.7

With "-F 0", the warning is also shown, and the parameter is also
configured as a floating point, but when I expand the parameter its
precision is set to the default 10 decimal places:

$ unset pi
$ typeset -F 0 pi=3.14159
typeset: invalid base (must be 2 to 36 inclusive): 0
$ echo $pi
0.0000000000
$ pi=2
$ echo $pi
2.0000000000

The behaviour I expect is that 'pi' should be rounded to one decimal place
with "-F 1", and to the nearest integer with "-F 0".  As a fabricated
example:

$ typeset -F 1 pi=3.14159
$ echo $pi
3.1
$ typeset -F 0 e=2.71828
$ echo $e
3

For values of "-F" greater than one, zsh behaves as I expect: no warnings
are issued, and the expanded value is rounded to the specified number of
places:

$ typeset -F 3 pi=3.14159
$ echo $pi
3.142

I have replicated this in zsh 5.0.5, and I do not see any related bug when
searching http://sourceforge.net/p/zsh/bugs/ for "typeset" or "float", so I
guess this issue is still extant in the dev version.

I didn't have enough C skill to understand the relevant parameter code and
structs from bin_typeset() down to typeset_setbase() within an hour, but
please let me know if I can provide more information at a simpler level.

             reply	other threads:[~2015-05-03 19:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-03 19:21 David Hughes [this message]
2015-05-03 20:36 ` PATCH: Fix two bugs in typeset_setbase Mikael Magnusson
2015-05-03 20:43   ` Mikael Magnusson
2015-05-03 21:24     ` Peter Stephenson
2015-05-03 22:40       ` Mikael Magnusson
2015-05-04  2:34         ` Mikael Magnusson

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=CAOcd6hrtTa7WVerarsU9+ZTWxa5G0g8f9Z+PGKCfMWZ7JWT-UA@mail.gmail.com \
    --to=dwhughes@gmail.com \
    --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).