zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: zsh-workers@sunsite.dk
Subject: questions - calling matheval() for printf
Date: Fri, 12 Oct 2001 15:03:45 +0100	[thread overview]
Message-ID: <3BC6F841.8AB53A42@yahoo.co.uk> (raw)

I have a few questions related to the use of matheval() for numeric
arguments to printf. According to the POSIX definition (which you can
read at http://www.opengroup.org/onlinepubs/007908799/xcu/printf.html),
with the %d format specification, and assuming 32-bit ints, the
following are the expect results:

argument	stdout		stderr
5a		5		printf: "5a" not completely converted
9999999999	2147483647	printf: "9999999999" arithmetic overflow
-9999999999	-2147483648	printf: "-9999999999" arithmetic overflow
ABC		0		printf: "ABC" expected numeric value

In the first case, the different error message doesn't worry me but
math evaluation doesn't return `5'. It is conceivable that someone
relies on this in a script, passing a string starting with a number and
redirecting stderr. I could successively chop characters off the right
of the string until matheval returns without an error. This would need
a hack to avoid repeated error messages from matheval(). Any other,
perhaps better suggestions?

Is there any way I can find out when arithmetic overflows have occurred
for the second and third cases? matheval() just allows the numbers to
wrap?

In the last case, we'll just have to be non-compliant (it returns $ABC)
but that doesn't worry me much.

What is going on with this errval and zerr/zwarn stuff? I don't
entirely understand which I should be calling on errors and whether I
am right to zero errval after calling matheval() and reading it?

Can a 64-bit integer be something other than long long? It seems I only
have ZSH_64_BIT_TYPE to check and it might need a different format
specifier for printf(3) if this is something other than long long.

Aside from this, using matheval() works very smoothly and it is
certainly better that we won't lose precision due to converting floats
via ASCII before formatting..

Oliver


             reply	other threads:[~2001-10-12 14:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-12 14:03 Oliver Kiddle [this message]
2001-10-12 14:19 ` Bart Schaefer
2001-10-15 12:54 ` Peter Stephenson
2001-10-15 17:11   ` Oliver Kiddle
2001-10-15 17:28     ` Peter Stephenson

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=3BC6F841.8AB53A42@yahoo.co.uk \
    --to=okiddle@yahoo.co.uk \
    --cc=zsh-workers@sunsite.dk \
    /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).