Re:Tell HN: C Experts Panel – Ask us anything about C
by thayne on Thursday April 16, 2020 @10:14AM
(#22889559)
oops, i meant the wrapping_* functions
[ Parent
| on HN ]
Re:Tell HN: C Experts Panel – Ask us anything about C
by flatfinger on Thursday April 16, 2020 @04:56PM
(#22893459)
If one wants a function that will compute xy/z when xy doesn't overflow, and yield some arbitrary value (but without other side-effects) when it does, wrapping functions will often be much slower than would be code that doesn't have to guarantee any particular value in case of overflow. If e.g. y is known to be 30 and z equal to 15, code using a wrapping multiply would need to be processed by multiplying the value by 30, computing a truncated the result, and dividing that by 15. If the program could use loosely-defined multiplication and division operators, however, the expression could be simplified to x+x.