From: Rich Felker <dalias@libc.org>
To: "jounijl@yahoo.co.uk" <jounijl@yahoo.co.uk>
Cc: musl@lists.openwall.com
Subject: Re: "Arithmetic exception" with modulus operator '%'
Date: Fri, 15 Feb 2019 12:21:15 -0500 [thread overview]
Message-ID: <20190215172115.GB23599@brightrain.aerifal.cx> (raw)
In-Reply-To: <490544eb-4170-0ce0-1dc0-9bc487e7cdc2@yahoo.co.uk>
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
next prev parent reply other threads:[~2019-02-15 17:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-15 3:35 jounijl
2019-02-14 23:58 ` Rich Felker
2019-02-15 10:31 ` jounijl
2019-02-15 17:21 ` Rich Felker [this message]
2019-02-15 10:05 ` Szabolcs Nagy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190215172115.GB23599@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=jounijl@yahoo.co.uk \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).