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

    From Waldek Hebisch@21:1/5 to Scott Lurndal on Mon Apr 28 10:12:29 2025
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Waldek Hebisch@21:1/5 to Scott Lurndal on Mon Apr 28 10:41:59 2025
    Scott Lurndal <scott@slp53.sl.home> wrote:
    Kaz Kylheku <643-408-1753@kylheku.com> writes:
    On 2025-04-27, 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.

    What does a good programmer do if they are asked to write
    a division routine for a run-time library called by other people's
    code?

    Or a programming language in which someone else can express a division >>whose denominator could be zero?

    Put a constraint in the documentation for the API specifying that
    division by zero is undefined[*] and take the processor fault,
    produce the core file and send it to the application developer with
    a big sign marked RTFM.

    That is fine if you are implementing language like C. But if
    you are implementing language for defining user extentions of
    a text editor, you do not want bugs in user code to crash the
    editor.

    --
    Waldek Hebisch

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Waldek Hebisch@21:1/5 to Bonita Montero on Mon Apr 28 10:39:07 2025
    Bonita Montero <Bonita.Montero@gmail.com> wrote:
    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.
    This C-addition exists since the beginning of the 1993, when NT
    3.1 was born. With Unix you'd have to use signals, wich are totally
    ugly since you couln't return to a different execution-context in
    the same function.

    I am not sure how much can be done with Posix functions, but any self-respectiong Unix allows you essentially the same freedom
    as hardware exception handler. That is you can change CPU registers
    and program memory in whatever way you need and then restart
    the program. If you change program counter to point to handler code
    within the faulting function, then you will restart the current
    function.

    Of course, C has no standard way to define a handler, for this you
    need different language or some nonstandard extention.

    --
    Waldek Hebisch

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Heathfield@21:1/5 to Waldek Hebisch on Wed Apr 30 08:36:03 2025
    On 28/04/2025 11:12, Waldek Hebisch wrote:

    <snip>

    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 {

    Like you said, not C.

    a = random();
    r = b/a;

    There's your mistake right there. You meant to say.

    while(!(a = random());
    return b/a;

    Half the code and without the bug.

    <snip>

    However, when hardware can detect
    error in division it is simpler to let hardware do the work.

    No doubt that was the reasoning that crippled the Yorktown.

    --
    Richard Heathfield
    Email: rjh at cpax dot org dot uk
    "Usenet is a strange place" - dmr 29 July 1999
    Sig line 4 vacant - apply within

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rosario19@21:1/5 to Waldek Hebisch on Wed Apr 30 09:16:42 2025
    On Mon, 28 Apr 2025 10:12:29 -0000 (UTC),(Waldek Hebisch) wrote:

    Scott Lurndal wrote:
    Bonita Montero writes:
    Am 27.04.2025 um 16:43 schrieb Kenny McCormack:
    In article <vulcf3$tsqb$1@raubtier-asyl.eternal-september.org>,
    Bonita Montero 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.

    im not agree, when error is detected it is need to be corrected in
    code, it is not a ardware yiussue
    could be better ardware make right computation as above you say and in
    some way programmer know that some error is in there

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)