I’m porting some C code which uses the gcc intrinsics to do a multiply/add with overflow checking. See here for reference. Is there a D equivalent?
Thread overview | |||||
---|---|---|---|---|---|
|
December 06, 2021 How to check for overflow when adding/multiplying numbers? | ||||
---|---|---|---|---|
| ||||
December 06, 2021 Re: How to check for overflow when adding/multiplying numbers? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dave P. | 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 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. |
December 06, 2021 Re: How to check for overflow when adding/multiplying numbers? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ola Fosheim Grøstad | 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: >I’m porting some C code which uses the gcc intrinsics to do a multiply/add with overflow checking. See here 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. That seems to fit the bill. Thanks! |