Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
inconsistent long number truncation
- X-seq: zsh-workers 43648
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: inconsistent long number truncation
- Date: Tue, 9 Oct 2018 07:50:14 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:mime-version :content-disposition:user-agent; bh=4Itj13KGAyfO3dsP3dqWAhVxxGLQwOiPJ51R7TelxIs=; b=rtG1y0WeAr8udUKbrxd/W8rZBPfhbOgzcu6Qir0jyoBbHOYSPqT+EP6wQZNkcu5JKJ JxaS3wTrGPNYJiYZWFSig/bOVBP91DAyJtScs8f0/AhVMYh7ODExOYYxLISEFAzEKHaX kqhKNWeu3iFIf2v9BHGvb0PRERjb3aaUAVn3gUYzx29KXpW6cww3uFVu1luRqRFialpC ZdDbjXdF5hWg9cFqArWA0EEtDtjTgjZH/gAwcysLGWLfxJOs3qIFrjsh9OL5aOxSBEkf enyvcSAoMp1JCdd9JXrUA9RiJ+3Cvk495a3Ngl4B6vBQQ+RnJtcSI71d4BYJXqEv8Thi hmtw==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mail-followup-to: Zsh hackers list <zsh-workers@xxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
From https://unix.stackexchange.com/a/474132
$ zsh -c 'echo $((12345678901234567890));echo $((12345678901234567890123))'
zsh:1: number truncated after 19 digits: 12345678901234567890
1234567890123456789
zsh:1: number truncated after 22 digits: 12345678901234567890123
-1363962815083169260
I think the:
newcalc = calc * base + *s - '0';
if (newcalc < calc)
Is an invalid way to check for numbers wrapping.
On GNU/Linux amd64
ulong 1234567890123456789*10 is
12345678901234567890 and:
(gdb) p calc
$7 = 12345678901234567890
(gdb) p calc*10
$8 = 12776324570088369204
(gdb) p calc*10*10
$9 = 17082781258626382344
(gdb) p calc*10*10*10
$10 = 4807115922877858896
Why do we truncate in the first place? That's hardly more useful
than letting the numbers wrap.
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author