Re: Did you get confused again? You seem eaily bewildered.

Liste des GroupesRevenir à cl c 
Sujet : Re: Did you get confused again? You seem eaily bewildered.
De : antispam (at) *nospam* fricas.org (Waldek Hebisch)
Groupes : comp.lang.c
Date : 28. Apr 2025, 11:12:29
Autres entêtes
Organisation : To protect and to server
Message-ID : <vunkab$1bp4h$1@paganini.bofh.team>
References : 1 2 3 4 5 6
User-Agent : tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.1.0-9-amd64 (x86_64))
Scott Lurndal <scott@slp53.sl.home> wrote:
Bonita Montero <Bonita.Montero@gmail.com> writes:
Am 27.04.2025 um 16:43 schrieb Kenny McCormack:
In article <vulcf3$tsqb$1@raubtier-asyl.eternal-september.org>,
Bonita Montero  <Bonita.Montero@gmail.com> wrote:
Am 27.04.2025 um 15:33 schrieb Bonita Montero:
>
The platform with the most comfortable handling of division by zeroes
is Windows. Win32 allows to catch that errors easily, whereas with
Posix it's hard to continue the code in the same function or with
a calling function.
>
#include <Windows.h>
 
Burp!
 
#include <stdio.h>
>
using namespace std;
 
Burp again!  Are you confused about which newsgroup this is?
>
Ignore it it you target a different platform. But it would be nice
if such problems were handleable that convenient in any lanugage.
 
Why?  I've -never- needed to handle a divide by zero;  a good programmer
won't let it happen.

When you want to compute something interesting zero disisors
appear naturally.  Of course, program needs some code to
handle them in alternative way.  One pattern which appear
looks in pseudo code (not C) like:

   while(true) {
      try {
          a = random();
          r = b/a;
          return r;
      }
   }

Of course, this is oversimplified, the point is that computation
depends on pseudo-random numbers.  When given number leads to
division by zero one needs to repeat computation with different
pseudo-random number.

Of course, if platform does not trap zero disisors, then one
needs explicit test.  And one needs some way to propagate
information from point of detection to appropriate handler.
One could use code like

struct div_res {bool valid; int quo; int rem;};

struct dive_res
do_div(int a, int b) {
    struct dive_res res = {false, 0, 0};
    if (b == 0 || (b == -1 && a == INT_MIN)) {
        return res;
    } else {
        res.quo = a/b;
        res.rem = a%b;
        res.valid = true;
        return res;
    }
}

and dully propagate information about failure to the point
where it can be handled.  However, when hardware can detect
error in division it is simpler to let hardware do the work.

--
                              Waldek Hebisch

Date Sujet#  Auteur
25 Apr 25 * integer divided by zero46Thiago Adams
25 Apr 25 +* Re: integer divided by zero6David Brown
25 Apr 25 i`* Re: integer divided by zero5Thiago Adams
25 Apr 25 i `* Re: integer divided by zero4Keith Thompson
26 Apr 25 i  `* Re: integer divided by zero3Thiago Adams
26 Apr 25 i   `* Re: integer divided by zero2Kenny McCormack
26 Apr 25 i    `- Re: integer divided by zero1Kaz Kylheku
25 Apr 25 +* Re: integer divided by zero9Keith Thompson
25 Apr 25 i+* Re: integer divided by zero6Thiago Adams
25 Apr 25 ii`* Re: integer divided by zero5Keith Thompson
25 Apr 25 ii +* Re: integer divided by zero3Kaz Kylheku
26 Apr 25 ii i`* Re: integer divided by zero2Keith Thompson
14 May 25 ii i `- Re: integer divided by zero1Tim Rentsch
28 Apr 25 ii `- Re: integer divided by zero1Thiago Adams
30 Apr 25 i`* Re: integer divided by zero2Rosario19
30 Apr 25 i `- Re: integer divided by zero1David Brown
25 Apr 25 +- Re: integer divided by zero1John McCue
26 Apr 25 +- Re: integer divided by zero1Waldek Hebisch
27 Apr 25 +* Re: integer divided by zero24Bonita Montero
27 Apr 25 i+* Re: integer divided by zero11Bonita Montero
27 Apr 25 ii`* Did you get confused again? You seem eaily bewildered. (Was: integer divided by zero)10Kenny McCormack
27 Apr 25 ii `* Re: Did you get confused again? You seem eaily bewildered. (Was: integer divided by zero)9Bonita Montero
27 Apr 25 ii  +* Re: Did you get confused again? You seem eaily bewildered. (Was: integer divided by zero)3Kaz Kylheku
27 Apr 25 ii  i+- Re: Did you get confused again? You seem eaily bewildered. (Was: integer divided by zero)1Bonita Montero
28 Apr 25 ii  i`- Re: Did you get confused again? You seem eaily bewildered.1Waldek Hebisch
28 Apr 25 ii  +* Re: Did you get confused again? You seem eaily bewildered.3Waldek Hebisch
30 Apr 25 ii  i+- Re: Did you get confused again? You seem eaily bewildered.1Rosario19
30 Apr 25 ii  i`- Re: Did you get confused again? You seem eaily bewildered.1Richard Heathfield
28 Apr 25 ii  `* Re: Did you get confused again? You seem eaily bewildered.2Waldek Hebisch
28 Apr 25 ii   `- Re: Did you get confused again? You seem eaily bewildered.1Bonita Montero
28 Apr 25 i+* Re: integer divided by zero4Richard Heathfield
28 Apr 25 ii`* Re: integer divided by zero3Bonita Montero
28 Apr 25 ii `* Re: integer divided by zero2Richard Heathfield
28 Apr 25 ii  `- Re: integer divided by zero1Bonita Montero
28 Apr 25 i`* Re: integer divided by zero8Richard Damon
28 Apr 25 i +* Re: integer divided by zero5Bonita Montero
28 Apr 25 i i+- Re: integer divided by zero1Bonita Montero
28 Apr 25 i i`* Re: integer divided by zero3Michael S
28 Apr 25 i i +- Re: integer divided by zero1Bonita Montero
28 Apr 25 i i `- Re: integer divided by zero1Muttley
28 Apr 25 i `* Re: integer divided by zero2Waldek Hebisch
28 Apr 25 i  `- Re: integer divided by zero1Bonita Montero
28 Apr 25 +* Re: integer divided by zero2Richard Heathfield
28 Apr 25 i`- Re: integer divided by zero1Keith Thompson
3 May 25 `* Re: integer divided by zero2Vir Campestris
3 May 25  `- Re: integer divided by zero1Michael S

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal