Deutsch English Français Italiano |
<vut1td$53kp$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: David Brown <david.brown@hesbynett.no> Newsgroups: comp.lang.c Subject: Re: integer divided by zero Date: Wed, 30 Apr 2025 13:35:09 +0200 Organization: A noiseless patient Spider Lines: 34 Message-ID: <vut1td$53kp$1@dont-email.me> References: <vughb7$g6cm$1@dont-email.me> <87selwoydy.fsf@nosuchdomain.example.com> <c7v31k1rtn411re7qa6q0jm1hrjl9li7po@4ax.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Wed, 30 Apr 2025 13:35:14 +0200 (CEST) Injection-Info: dont-email.me; posting-host="cc9518a6979defc66e3110f6f2f87cab"; logging-data="167577"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18El9B7y75BJ+vC3wAe1NO8iAF3g43lXbc=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Cancel-Lock: sha1:6ZoJR+WhwzE0Rwas/p9UYUq6XNg= Content-Language: en-GB In-Reply-To: <c7v31k1rtn411re7qa6q0jm1hrjl9li7po@4ax.com> Bytes: 2349 On 30/04/2025 12:41, Rosario19 wrote: > 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 = time(NULL) / 1000000000; >> int zero = one - 1; >> int ratio = one / zero; >> printf("%d\n", ratio); > > in math > 1/0 has to be +infinite ( for approximation +INT_MAX for C?) In common mathematics, 1 / 0 is undefined - just like in C. If you extend the set of real numbers to include some kind of infinity ∞ , you immediately lose many other useful properties of the set. INT_MAX is not a good approximation - there is no int value that makes sense for the result of 1 / 0.