Re: division by 7 without using division operator
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Tue, 06 Feb 2007 07:05:16 +0000
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.
.
- Follow-Ups:
- Re: division by 7 without using division operator
- From: Harald van Dijk
- Re: division by 7 without using division operator
- From: CBFalconer
- Re: division by 7 without using division operator
- References:
- division by 7 without using division operator
- From: krypto . wizard
- Re: division by 7 without using division operator
- From: Francois Grieu
- Re: division by 7 without using division operator
- From: *** T. Winter
- Re: division by 7 without using division operator
- From: CBFalconer
- division by 7 without using division operator
- Prev by Date: Re: Safe C library
- Next by Date: Re: division by 7 without using division operator
- Previous by thread: Re: division by 7 without using division operator
- Next by thread: Re: division by 7 without using division operator
- Index(es):