From owner-svn-src-head@freebsd.org Wed Jun 1 13:57:04 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1A2C0B60C1D; Wed, 1 Jun 2016 13:57:04 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail107.syd.optusnet.com.au (mail107.syd.optusnet.com.au [211.29.132.53]) by mx1.freebsd.org (Postfix) with ESMTP id D9ADB1115; Wed, 1 Jun 2016 13:57:03 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from c122-106-149-109.carlnfd1.nsw.optusnet.com.au (c122-106-149-109.carlnfd1.nsw.optusnet.com.au [122.106.149.109]) by mail107.syd.optusnet.com.au (Postfix) with ESMTPS id 9E834D4A66D; Wed, 1 Jun 2016 23:56:59 +1000 (AEST) Date: Wed, 1 Jun 2016 23:56:58 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Chris Torek cc: Bruce Evans , Andrey Chernov , pfg@freebsd.org, src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r300956 - head/lib/libc/stdlib In-Reply-To: <201605312124.u4VLOhnI085631@elf.torek.net> Message-ID: <20160601232109.D2616@besplex.bde.org> References: <201605312124.u4VLOhnI085631@elf.torek.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=M8SwUHEs c=1 sm=1 tr=0 a=R/f3m204ZbWUO/0rwPSMPw==:117 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=kj9zAlcOel0A:10 a=bx8du_89sgTnowQVBh0A:9 a=CjuIK1q_8ugA:10 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Jun 2016 13:57:04 -0000 On Tue, 31 May 2016, Chris Torek wrote: >> That was what I was complaining about. div.c is for C90 (misspelled >> "ANSI"). > > It wasn't misspelled when I wrote it. :-) The 1989 ANSI C :-) > standard was formally ratified in Dec 1989, and the draft was > pretty firm by the time I wrote the code (which I am sure was also > 1989, despite the 1990 copyright; we added or updated all the > copyrights at the last minute, for net-2). ISO's quick adoption, > and hence the name C90, post-date all of that. The weren't quick enough to be in the same year. I usually spell the year as 90, but this can be confusing when discussing the compiler c89 or the compiler flag -std=c89. Hmm, old gcc doesn't have -std=c90, but clang does. >> >> Correct rounding for a >> positive divisor is towards minus infinity so that the remainder is >> not negative. This is modulo arithmetic and has good algebraic >> properties. C99 requires rounding minus infinity, at least for positive >> divisors, under the extension "reliable integer division". > > Did you state this backwards? For integer divison I see: Oops. I seem to have misedited a whole clause. "towards" is also missing. > When integers are divided, the result of the / operator is the > algebraic quotient with any fractional part discarded.[105] If > the quotient a/b is representable, the expression (a/b)*b + a%b > shall equal a; otherwise, the behavior of both a/b and a%b is > undefined. > > which (as footnote 105 notes) is "truncation towards zero", so that > (-1)/2 is 0 and not -1. > >> In C90, >> the rounding is implementation-defined, so it may be correct, but it >> is "unreliable" since it can be anything. >> >> In C90, div() is specified as giving "reliable" division, and that is >> what the fixups implement. This now wastes time to change nothing. > > Right -- as long as the compiler must meet C99 rules, div.c > can just use the / and % operators. ache added the ifdef. I checked that compilers (old gcc and current clang on amd64) don't auto-inline div(). It is very suitable for inlining without the fixup. Bruce