zsh-workers
 help / color / mirror / code / Atom feed
From: Wayne Davison <wayned@users.sourceforge.net>
To: Zsh hackers list <zsh-workers@sunsite.dk>
Subject: Re: PATCH: my "SECONDS can be floating point" tweaks
Date: Thu, 31 Oct 2002 10:53:01 -0800	[thread overview]
Message-ID: <20021031185301.GD8814@scuzzy.blorf.net> (raw)
In-Reply-To: <1021031050931.ZM5514@candle.brasslantern.com>

On Thu, Oct 31, 2002 at 05:09:31AM +0000, Bart Schaefer wrote:
> Is converting to float and then back to integer (or the other way round
> for the setfn) really going to give the same results as a computation
> directly on only shtimer.tv_sec?

Not the same but more accurate.  For example:  if the script starts in
second "5" (long ago) .9 seconds into that second and the script
references $SECONDS .2 seconds later, the old version would report that
we've been running for 1 second.  The new version would report 0 seconds
have elapsed until we get .9 seconds into second "6".  So, the new
method causes the time to be calculated more accurately and then the
decimal points just get truncated (as you surmised: the value is not
rounded).

> I don't follow what this means from the point of view of the _caller_
> of a function in which SECONDS is local.

What it means is that the parent function's variable remains unaffected
by any child's local parameter.  Before this change the parent's value
could get more and more inaccurate each time a local value was used and
then added into the parent's value.  I.e., the old method was to save
off the elapsed time (say "8" seconds), run the local function, at which
point we add in the elapsed time of the child function (say "1") to our
value and then reset the SECONDS variable in the parent (setting it to
"9").  If we were near a second boundary in either the saving of the "8"
or the adding of the "1", the real value could easily be 1 second off
(i.e. "10"), but that should be a fairly rare error (I would imagine).
Switching the parent into float for better accuracy would (I believe)
cause a steady stream of micro-seconds errors from each child to
accumulate at a very slow rate (since the time used in the code that
saves the parent value and adds the child value contains untimed
sections).

The new code just remembers the real start time of the parent's variable
and restores it, so the value remains unchanged no matter how many calls
are made.

..wayne..


  reply	other threads:[~2002-10-31 18:54 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-28 18:55 PATCH: SECONDS can be floating point Peter Stephenson
2002-10-29 10:40 ` Peter Stephenson
2002-10-29 11:23   ` Peter Stephenson
2002-10-29 17:52     ` Wayne Davison
2002-10-29 18:08     ` Wayne Davison
2002-10-29 18:13       ` Peter Stephenson
2002-10-30 21:17 ` PATCH: my "SECONDS can be floating point" tweaks Wayne Davison
2002-10-31  5:09   ` Bart Schaefer
2002-10-31 18:53     ` Wayne Davison [this message]
2002-10-31 10:34   ` Peter Stephenson
2002-10-31 18:53     ` Wayne Davison

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=20021031185301.GD8814@scuzzy.blorf.net \
    --to=wayned@users.sourceforge.net \
    --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).