• Re: integer divided by zero

    From goldside000@outlook.com@3:633/280.2 to All on Sun Jun 1 04:56:45 2025
    Thiago Adams <thiago.adams@gmail.com> wrote:
    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.


    Yeah, I cannot think of an architecture where dividing by zero doesn't
    result in an exception or error of some sort. But there's ARM, where it
    might return 0, the dividend, or just garbage.

    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: A noiseless patient Spider (3:633/280.2@fidonet)
  • From Keith Thompson@3:633/280.2 to All on Sun Jun 1 07:07:02 2025
    goldside000@outlook.com writes:
    Thiago Adams <thiago.adams@gmail.com> wrote:
    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.

    Yeah, I cannot think of an architecture where dividing by zero doesn't
    result in an exception or error of some sort. But there's ARM, where it
    might return 0, the dividend, or just garbage.

    Yes, I mentioned that in this thread more than a month ago. On two
    Linux AARM64 systems I've tried, dividing an integer by zero in a
    non-constant expression yields 0.

    --
    Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
    void Void(void) { Void(); } /* The recursive call of the void */

    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: None to speak of (3:633/280.2@fidonet)
  • From Scott Lurndal@3:633/280.2 to All on Sun Jun 1 07:53:31 2025
    Reply-To: slp53@pacbell.net

    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
    goldside000@outlook.com writes:
    Thiago Adams <thiago.adams@gmail.com> wrote:
    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.

    Yeah, I cannot think of an architecture where dividing by zero doesn't
    result in an exception or error of some sort. But there's ARM, where it
    might return 0, the dividend, or just garbage.

    Yes, I mentioned that in this thread more than a month ago. On two
    Linux AARM64 systems I've tried, dividing an integer by zero in a >non-constant expression yields 0.


    From the ARMv8 Architecture Reference Manual (DDI0487)

    If a signed integer division (INT_MIN / -1) is performed
    where INT_MIN is the most negative integer value representable
    in the selected register size, then the result overflows the
    signed integer range. No indication of this overflow is produced
    and the result that is written to the destination register is INT_MIN.

    A division by zero results in a zero being written to the destination
    register, without any indication that the division by zero occurred.


    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: UsenetServer - www.usenetserver.com (3:633/280.2@fidonet)