Deutsch   English   Français   Italiano  
<c7v31k1rtn411re7qa6q0jm1hrjl9li7po@4ax.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Rosario19 <Ros@invalid.invalid>
Newsgroups: comp.lang.c
Subject: Re: integer divided by zero
Date: Wed, 30 Apr 2025 12:41:15 +0200
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <c7v31k1rtn411re7qa6q0jm1hrjl9li7po@4ax.com>
References: <vughb7$g6cm$1@dont-email.me> <87selwoydy.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
Injection-Date: Wed, 30 Apr 2025 12:41:16 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="1cc58dbe40ed977f55b3be139629d7c5";
	logging-data="121608"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18TzoOH0lE0iWj72C8lmNieQDtFSb28w5E="
Cancel-Lock: sha1:bnHXEfZ6z1AB/YViO+BcqWC1BUU=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)

On Fri, 25 Apr 2025 12:05:13 -0700, Keith Thompson wrote:

>Thiago Adams writes:
>> Does anyone know of any platform where integer division by zero
>> returns a number, or in other words, where it's not treated as an
>> error? I'm asking because division by zero is undefined behaviour, but
>> I think division by a constant zero should be a constraint instead.
>
>Division by a constant zero is a constraint violation in a context that
>requires a constant expression.
>
>I wrote this quick and dirty program:
>
>#include <stdio.h>
>#include <time.h>
>int main(void) {
>    int one =3D time(NULL) / 1000000000;
>    int zero =3D one - 1;
>    int ratio =3D one / zero;
>    printf("%d\n", ratio);

in math
1/0 has to be +infinite ( for approximation +INT_MAX for C?)
but should be one error if one want one infinite array long=20
as in "int a[1/0]" or want to do infinite/0 infinite-inifinite
infinite/infinite ecc could be ok if one make infinite+infinite=3D
infinite, infinite * infinite =3D infinite ecc



>}
>
>It's not portable, but on the systems where I've tried it it sets
>one to 1 and zero to 0 in a way that the compiler can't detect,
>so the division won't be optimized away.  (At least, it does so if
>you run it between 2001 and 2286.)
>
>On x86_64, it dies with a floating point exception.
>
>On aarch64, it prints 0.