mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Re: math argument reduction
Date: Sun, 26 Jun 2011 14:33:44 -0400	[thread overview]
Message-ID: <20110626183344.GX12592@brightrain.aerifal.cx> (raw)
In-Reply-To: <20110626180402.GX27421@port70.net>

On Sun, Jun 26, 2011 at 08:04:02PM +0200, Szabolcs Nagy wrote:
> dalias, i thought about the simple argument reduction method
> you proposed on irc, imho it won't be that good
> 
> the task is to calculate X mod M, so to get the fractional part of
> x = X/M
> you said you would treat X as a sum (of 2^n terms) let's say
> X = A+B
> and assume we have precalculated a=A/M and b=B/M in a table, then
> x = a+b
> is easy to get
> 
> but it well might be that the form of a+b is
> 
> [..]1011 . 0000000000000001101011[..]
> 
> so the fractional part has many leading zeros
> (it can be as many as 61) so you need to store a and b
> with large precision to get good floating point representation
> of the fractional part
> (53 + 61 bits precision + some extra bits for rounding)
> 
> so you need to store and do arithmetics with 120bit fixpoint values

I think you misunderstood my algorithm. You never need to compute X/M.
It's A%M and B%M, not A/M and B/M, which you have precalculated in
your tables. And therefore, (A+B)%M is congruent to A%M + B%M. In
general it could be outside the interval [0,M), but not by so much
that it's hard to get a good answer.

Rich


  reply	other threads:[~2011-06-26 18:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-26 18:04 Szabolcs Nagy
2011-06-26 18:33 ` Rich Felker [this message]
2011-06-26 18:51   ` Szabolcs Nagy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110626183344.GX12592@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).