zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-workers@zsh.org
Subject: Re: Patch for giga- and terabyte size specifiers
Date: Wed, 19 Feb 2014 13:52:42 +0000	[thread overview]
Message-ID: <20140219135242.47240238@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <201402191412030328.00E5C601@localhost>

On Wed, 19 Feb 2014 14:12:03 +0100
Manuel Presnitz <mpy@gmx.net> wrote:
> I thought it is time to have globbing size specifiers at hand also for
> gigabytes, and while at it for terabytes, too.  As that seemed pretty
> straight forward, I tried to do the modification myself.

Generally looks fine, thanks...

> +#if defined(ZSH_64_BIT_TYPE) || defined(LONG_IS_64_BIT)
> +    case TT_GIGABYTES:
> +        scaled += 1073741823l;
> +        scaled /= 1073741824l;
> +        break;
> +    case TT_TERABYTES:
> +        scaled += 1099511627775l;
> +        scaled /= 1099511627776l;
> +        break;
> +#endif

I suppose we need to be a bit careful here since we don't know the
64-bit type is long, so the suffix may not be right and we might get
overflow of the constant.

I'm not sure if we get away with e.g.

(zlong)1099511627775

--- my C basics aren't up to remembering whether the compiler is
required to look at the type of a cast when interpreting a constant,
but I have a suspicion it isn't.

Otherwise, I guess we need something like...

#if defined(ZSH_64_BIT_TYPE) || defined(LONG_IS_64_BIT)
#ifdef LONG_IS_64_BIT
#define ZLONG_CONST(x)  x ## l
#else
#define ZLONG_CONST(x)  x ## ll
#endif
    case TT_GIGABYTES:
        scaled += ZLONG_CONST(1073741823);
        scaled /= ZLONG_CONST(1073741824);
        break;
    case TT_TERABYTES:
        scaled += ZLONG_CONST(1099511627775);
        scaled /= ZLONG_CONST(1099511627776);
        break;
#endif

although probably even that doesn't work for the mysterious "quad" type
mentioned in some bits of the shell.  Or maybe I'm being too pernickety.

(I have a feeling this is all done much better in D :-/)

pws


  reply	other threads:[~2014-02-19 13:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-19 13:12 Manuel Presnitz
2014-02-19 13:52 ` Peter Stephenson [this message]
2014-02-19 20:03   ` 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=20140219135242.47240238@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.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).