www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - VRP and division/remainder by 0

reply deadalnix <deadalnix gmail.com> writes:
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
next sibling parent reply Jonathan M Davis via Digitalmars-d <digitalmars-d puremagic.com> writes:
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
parent deadalnix <deadalnix gmail.com> writes:
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 Davis
Yup, also, consider : a == 0 ? b : 10 / a
Jul 03 2016
prev sibling parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
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