On Tue, May 2, 2023 at 8:03 AM <jmsa...@gmail.com> wrote:

> > I think this example shows that you don't need any special infrastructure
> > from numpy. I don't think there is going to be much appetite to expand
> our
> > API in this direction.
>
> But I do! I'm looking for something that implements the
> multiply_check_ov(X,Y) and similar functionality for addition and
> subtraction, for large arrays; I don't know how to do that efficiently. (Or
> even correctly for 64-bit operands --- for 8/16/32 I suppose as a baseline
> I could do the math in 64-bit arithmetic and if the answer doesn't match,
> then use the sign bit of the 64-bit result for determining overflow.)
>

Some C compilers provide some builtin functions that do this for you, and
some cross-platform headers around that show how to do this.

https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html
https://github.com/pytorch/pytorch/blob/main/c10/util/safe_numerics.h
https://github.com/dcleblanc/SafeInt

-- 
Robert Kern
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to