digitalmars.D.learn - How to check for overflow when adding/multiplying numbers?
- Dave P. (3/3) Dec 06 2021 I’m porting some C code which uses the gcc intrinsics to do a
- Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= (4/7) Dec 06 2021 There is:
- Dave P. (4/11) Dec 06 2021 That seems to fit the bill.
I’m porting some C code which uses the gcc intrinsics to do a multiply/add with overflow checking. See [here](https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html) for reference. Is there a D equivalent?
Dec 06 2021
On Monday, 6 December 2021 at 17:46:35 UTC, Dave P. wrote:I’m porting some C code which uses the gcc intrinsics to do a multiply/add with overflow checking. See [here](https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html) for reference. Is there a D equivalent?There is: https://dlang.org/phobos/core_checkedint.html I have never used it, so I don't know how well it performs.
Dec 06 2021
On Monday, 6 December 2021 at 18:38:37 UTC, Ola Fosheim Grøstad wrote:On Monday, 6 December 2021 at 17:46:35 UTC, Dave P. wrote:That seems to fit the bill. Thanks!I’m porting some C code which uses the gcc intrinsics to do a multiply/add with overflow checking. See [here](https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html) for reference. Is there a D equivalent?There is: https://dlang.org/phobos/core_checkedint.html I have never used it, so I don't know how well it performs.
Dec 06 2021