From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13805 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: "Arithmetic exception" with modulus operator '%' Date: Fri, 15 Feb 2019 12:21:15 -0500 Message-ID: <20190215172115.GB23599@brightrain.aerifal.cx> References: <20190214235814.GY23599@brightrain.aerifal.cx> <490544eb-4170-0ce0-1dc0-9bc487e7cdc2@yahoo.co.uk> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="113845"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.5.21 (2010-09-15) Cc: musl@lists.openwall.com To: "jounijl@yahoo.co.uk" Original-X-From: musl-return-13821-gllmg-musl=m.gmane.org@lists.openwall.com Fri Feb 15 18:21:35 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1guhB8-000TRg-1x for gllmg-musl@m.gmane.org; Fri, 15 Feb 2019 18:21:34 +0100 Original-Received: (qmail 24209 invoked by uid 550); 15 Feb 2019 17:21:31 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 24191 invoked from network); 15 Feb 2019 17:21:30 -0000 Content-Disposition: inline In-Reply-To: <490544eb-4170-0ce0-1dc0-9bc487e7cdc2@yahoo.co.uk> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:13805 Archived-At: On Fri, Feb 15, 2019 at 10:31:22AM +0000, jounijl@yahoo.co.uk wrote: > > Exactly. To be complite: > > The host machine prints: "Floating point exception" and outputs a > core file. Uses: /lib/libc.so.7 > The Alpine prints: "Arithmetic exception".  Uses: /lib/ld-musl-x86_64.so.1 > Solaris 10 prints: "Arithmetic exception". Uses: /lib/libc.so.1 ; > /lib/libm.so.2 > Ubuntu prints: "Floating point exception" and outputs a core file. > Uses: /lib/x86_64-linux-gnu/libc.so.6 > > To the question "what do you except": > Of course the behaviour is similar to others and this is correct. As > in programs the behaviour would be best like this: number%zero would > be the number it self when number/zero is undefined or infinity > (maby set the number to the largest known number). To change this, > some mathematical evaluation would be needed. Answer: mod 0: > Convenient would be the number it self ? This has nothing to do with musl or library implementation; what you're asking for is a *compiler* that defines certain undefined behavior in a particular way. Even if you had such a thing, writing C code in order to depend on nonstandard behavior of a particular compiler would not be a reasonable thing to do. A better way to achieve the same thing would be just writing a function that does what you want: int my_mod(int a, int b) { if (!b) return a; else if (b==-1) return 0; else return a%b; } and using that instead of using the % operator directly. If you need it to work in constant expression contexts, you could use a macro instead: #define MY_MOD(a,b) (!(b) ? (a) : (b)==-1 ? 0 : (a)%(b)) Rich