digitalmars.D - VRP and division/remainder by 0
- deadalnix (8/8) Jul 03 2016 Question is, what should VRP do when the denum range contains 0 ?
- Jonathan M Davis via Digitalmars-d (7/15) Jul 03 2016 I confess that my first thought was that it should just result in an err...
- deadalnix (3/10) Jul 03 2016 Yup, also, consider :
- Andrei Alexandrescu (2/10) Jul 04 2016 I think 1 works best for both / and %. -- Andrei
Question is, what should VRP do when the denum range contains 0 ? I see 2 way forward: - 0 will fault, so not yield a result - hardware will fault. It can be ignored when doing VRP. - denum with 0 return a full range for division, union result's range while ignoring 0 and num range for remainder. Doing 1/ for division and 2/ for remainder seems to be the best choice to me. Thought ?
Jul 03 2016
On Sunday, July 03, 2016 23:18:58 deadalnix via Digitalmars-d wrote:Question is, what should VRP do when the denum range contains 0 ? I see 2 way forward: - 0 will fault, so not yield a result - hardware will fault. It can be ignored when doing VRP. - denum with 0 return a full range for division, union result's range while ignoring 0 and num range for remainder. Doing 1/ for division and 2/ for remainder seems to be the best choice to me. Thought ?I confess that my first thought was that it should just result in an error, since it's obviously wrong, but then you have an error that depends on how good VRP is, which may not be a great idea. Still, I don't see any reason why you'd want it to actually compile when it's obviously going to crash the program if it's ever hit. - Jonathan M Davis
Jul 03 2016
On Monday, 4 July 2016 at 00:58:49 UTC, Jonathan M Davis wrote:I confess that my first thought was that it should just result in an error, since it's obviously wrong, but then you have an error that depends on how good VRP is, which may not be a great idea. Still, I don't see any reason why you'd want it to actually compile when it's obviously going to crash the program if it's ever hit. - Jonathan M DavisYup, also, consider : a == 0 ? b : 10 / a
Jul 03 2016
On 7/3/16 7:18 PM, deadalnix wrote:Question is, what should VRP do when the denum range contains 0 ? I see 2 way forward: - 0 will fault, so not yield a result - hardware will fault. It can be ignored when doing VRP. - denum with 0 return a full range for division, union result's range while ignoring 0 and num range for remainder. Doing 1/ for division and 2/ for remainder seems to be the best choice to me. Thought ?I think 1 works best for both / and %. -- Andrei
Jul 04 2016