From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13804 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: "jounijl@yahoo.co.uk" Newsgroups: gmane.linux.lib.musl.general Subject: Re: "Arithmetic exception" with modulus operator '%' Date: Fri, 15 Feb 2019 10:31:22 +0000 Message-ID: <490544eb-4170-0ce0-1dc0-9bc487e7cdc2@yahoo.co.uk> References: <20190214235814.GY23599@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="109810"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 Cc: musl@lists.openwall.com To: Rich Felker Original-X-From: musl-return-13820-gllmg-musl=m.gmane.org@lists.openwall.com Fri Feb 15 11:32:46 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 1guanU-000SOt-Vi for gllmg-musl@m.gmane.org; Fri, 15 Feb 2019 11:32:45 +0100 Original-Received: (qmail 19854 invoked by uid 550); 15 Feb 2019 10:32:42 -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 19835 invoked from network); 15 Feb 2019 10:32:42 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1550226750; bh=E3FIqe32swBnViryYf8CjGNLRwvnDXIBNYhO7nLWJnE=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject; b=tw2mDrRBhmUJ3OXPrl0K/yqQyVdvhGkhfDHsuFzHIrAKeE9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9LFtgvpYHSBlI8zF3yqZ7IpQT2aOit.eUlveFOvpjiW_QQdxm_NBGgBrOUEpij 7Bbxv8WW9cu7JKhoH.9F8VA9v7c9E46BfwB_PhtwCK In-Reply-To: <20190214235814.GY23599@brightrain.aerifal.cx> Content-Language: en-US Xref: news.gmane.org gmane.linux.lib.musl.general:13804 Archived-At: 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 ? Maby the core file has to be enabled somehow. Attached is a complite test program. The word "trap" is unfamiliar to me. I think it means just checking with an 'if'-like comparison. Thank you for the replies. It helped. The simple facts are not always obvious. Jouni the file: $ cat m.c #include int    main( int argc, char *argv[] ); int    main( int argc, char *argv[] ){         unsigned int z = 0;         unsigned int w = 0;         //floating point exception: fprintf( stderr, "\n 0 %% 0 = %i", (int) z%w );         z = 1;         //floating point exception: fprintf( stderr, "\n 1 %% 0 = %i", (int) z%w );         z = 0; w = 1;         fprintf( stderr, "\n 0 %% 1 = %i", (int) z%w );         z = 1; w = 1;         fprintf( stderr, "\n 1 %% 1 = %i", (int) z%w ); } On 14.2.2019 23.58, Rich Felker wrote: > On Fri, Feb 15, 2019 at 03:35:23AM +0000, jounijl@yahoo.co.uk wrote: >> As in the headline. Program stops and prints "Arithmetic exception" >> at the line where the modulus operator '%' is. >> >> I'm compiling in Alpine linux with clang installed from apk:s: >> >> clang -c test.c >> clang -o test test.o >> >> The code is: >> >> ----- snip ----- >>         unsigned int unum  = 0; >>         unsigned int umod  = 0; >>         unsigned int ures  = 0; >>         ures = unum % umod; // <-- this one >> ----- /snip ----- >> >> The variables have some values other than 0. > I don't follow. You say they have some value other than 0, but the > above example snippet has them as zero, and if they're 0 it's > undefined behavior and a fault of some sort is a typical result. What > did you expect to happen? > > Rich