Groups | Search | Server Info | Login | Register


Groups > comp.arch.arithmetic > #77

Re: New appromixation for integer division by 63 or 127

Newsgroups comp.arch.arithmetic
Date 2014-10-11 06:05 -0700
References <74d951ee-6fd2-43ad-8f0a-2852a031bd2c@googlegroups.com>
Message-ID <af2217af-30fe-42e2-bc0d-1a9bf6847c35@googlegroups.com> (permalink)
Subject Re: New appromixation for integer division by 63 or 127
From nikolaos.kavvadias@gmail.com

Show all headers | View raw


I have updated my claims for the algorithm. It works for all tested constant divisors (n=2 to n=16), and given the following assumption:

the range for x is [0,2^(2*n)-2], i.e. for n = 6, the range indeed is 
0:4094. 

And a test program: 

[code] 
#include <stdio.h> 
#include <stdlib.h> 
#include <math.h> 

/* main: 
 */ 
int main(void) 
{ 
  int qapprox, qexact; 
  int i, j, k; 

  for (i = 2; i < 8; i++) { 
    for (j = 1; j < (1<<i)*(1<<i)-1; j++) { 
      k = (1<<i) - 1; 
      qapprox = (((j>>i)+j+((1<<i)+1))>>i)-1; 
      qexact  = j / k; 
      if (qapprox != qexact) { 
        fprintf(stderr, "qapprox = (%d/%d) = %d\tqexact = (%d/%d) = %d\n", 
          j, k, qapprox, j, k, qexact); 
      } 
    } 
  } 
  return 0; 
} 
[/code]

Back to comp.arch.arithmetic | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

New appromixation for integer division by 63 or 127 nikolaos.kavvadias@gmail.com - 2014-10-11 00:19 -0700
  Re: New appromixation for integer division by 63 or 127 nikolaos.kavvadias@gmail.com - 2014-10-11 06:05 -0700
  Re: New appromixation for integer division by 63 or 127 Terje Mathisen <terje.mathisen@tmsw.no> - 2014-10-13 10:20 +0200
    Re: New appromixation for integer division by 63 or 127 nikolaos.kavvadias@gmail.com - 2014-10-15 01:09 -0700

csiph-web