Re: Dealing with possible overflows
From: Allan Bruce (allanmb_at_TAKEAWAYf2s.com)
Date: 08/02/04
- Next message: rohitash panda: "Re: array with a single element"
- Previous message: Eddie: "problem with dll"
- In reply to: MWB: "Dealing with possible overflows"
- Next in thread: Michael Mair: "Re: Dealing with possible overflows"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 2 Aug 2004 09:34:58 +0100
"MWB" <mandir_wahin_banayenge@yahoo.com> wrote in message
news:f498b759.0408012338.759e879c@posting.google.com...
> Hi CLC,
> Suppose I want to evaluate (x*y)/z where x,y,z are unsigned int's.
> In some cases, though (x*y) might overflow the (xy)/z (the actual
> product) might be representable as an unsigned int, I was wondering
> how to get the correct answer in such a case.
> In one specific case the answer is easy to see : x is the only "large"
> number among the three- y and z are small.
> Then calculate the answer as (x/z)*y + ((x -(x/z)*z)*y)/z
I would cast to a double for the calculation, and then back to unsigned int.
This is likely to be faster, and easier to understand.
Allan
- Next message: rohitash panda: "Re: array with a single element"
- Previous message: Eddie: "problem with dll"
- In reply to: MWB: "Dealing with possible overflows"
- Next in thread: Michael Mair: "Re: Dealing with possible overflows"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|