Date: Sat, 21 May 2016 15:00:44 -0700 From: Conrad Meyer <cem@FreeBSD.org> To: Bruce Evans <brde@optusnet.com.au> Cc: Konstantin Belousov <kib@freebsd.org>, src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r300332 - in head/sys: amd64/amd64 i386/i386 Message-ID: <CAG6CVpVZd-2wm_0NKggXjDQMnTvhqRM9sGCLEzyCgA7kwO3gww@mail.gmail.com> In-Reply-To: <20160521123908.V1914@besplex.bde.org> References: <201605201950.u4KJoWA5028092@repo.freebsd.org> <20160521081930.I1098@besplex.bde.org> <CAG6CVpUtz49L0VWfPcCXFvEMiV41AwxhJ8tGjenLqgPJt_kpyA@mail.gmail.com> <20160521103528.I1539@besplex.bde.org> <CAG6CVpXoTxFyo_-mD5NfpUEHJmxrrry6Nnw-Hr5mR0z2_JzHrQ@mail.gmail.com> <20160521123908.V1914@besplex.bde.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, May 20, 2016 at 9:13 PM, Bruce Evans <brde@optusnet.com.au> wrote: > On Fri, 20 May 2016, Conrad Meyer wrote: > >> On Fri, May 20, 2016 at 6:10 PM, Bruce Evans <brde@optusnet.com.au> wrote: >>> >>> >>> Signed integers are easier to understand provided calculations with them >>> don't overflow. >> >> >> How? > > > For the same reasons as in applying mathematics. Applying mathematics > was harder before negative numbers were invented. Negative numbers > are actually not easy to understand at the technical level (the usual > representation of them is equivalence classes of pairs of non-negative > numbers), but their properties are easy to understand and work with > once you are familiar with them and don't think about their > implementation details too much. > > Ordinary (real) numbers (including negative ones) also have good ordering > properties for all operations. > > Computer arithmetic can't represent all ordinary numbers, but gets closest > by representing ordinary integers as C signed integers perfectly when no > overflow occurs. > > By using C unsigned integers unnecessarily, you throw out invention of > negative numbers and might have to work with the unfamiliar and badly > behaved ordering on them. C programmers have some experience with this > ordering, but apparently not enough to usually avoid bugs. > >> The rest of the argument seems to be, using u_int is bad because more >> unsigned is always bad. But I haven't seen a good reason to believe >> that is so. > > > Not always bad. Sometimes you must use C unsigned integers to get a full > representation without wasting many bits, or actually want the ordering > of unsigned integers. The main case is representing other C things like > pointers. Differences of pointers are still hard to handle. > > Bruce Thanks for explaining. Can you explain a little bit about the badly behaved ordering of unsigned integers? I am not familiar with that. Best, Conrad
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAG6CVpVZd-2wm_0NKggXjDQMnTvhqRM9sGCLEzyCgA7kwO3gww>