zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: inconsistent long number truncation
Date: Tue, 9 Oct 2018 13:30:04 +0000	[thread overview]
Message-ID: <20181009133004.olzmetmg2vkzxg6l@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <20181009065014.6rxe67ophjq6j6vs@chaz.gmail.com>

Stephane Chazelas wrote on Tue, Oct 09, 2018 at 07:50:14 +0100:
> I think the:
> 
> 
>           newcalc = calc * base + *s - '0';
>           if (newcalc < calc)
> 
> Is an invalid way to check for numbers wrapping.
> 

Obviously right, as your examples show:

> (gdb) p calc
> $7 = 12345678901234567890
> (gdb) p calc*10
> $8 = 12776324570088369204

> Why do we truncate in the first place?

Judging by the comment at the top of the function, might that be for
compatibility with some strtol() implementation [that once was] out there?

      reply	other threads:[~2018-10-09 13:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-09  6:50 Stephane Chazelas
2018-10-09 13:30 ` Daniel Shahaf [this message]

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=20181009133004.olzmetmg2vkzxg6l@tarpaulin.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --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).