Re: division by 7 without using division operator



CBFalconer said:

"*** T. Winter" wrote:
"Francois Grieu" <fgrieu@xxxxxxxxx> writes:
...
To suceed in these interviews, I fear that you must not be so
smart as to outsmart the person asking the questions. So I
suspect the right answer might have been

number *= 0.142857142857143; // divide by 7

which indeed, in quite a few contexts, is an approriate answer.

Indeed, it gives the correct answer for all integers from 0 to
2147483647.

And probably down to -2147483648.

An exercise for those with way too much time on their hands: what is the
smallest-magnitude integer (i.e. regardless of sign) for which it
fails? If this number is negative, what is the smallest *positive*
integer for which it fails?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
.