6

In the C99 spec it says of remquo:

The remquo functions are intended for implementing argument reductions which can exploit a few low-order bits of the quotient. Note that x may be so large in magnitude relative to y that an exact representation of the quotient is not practical.

What is an "argument reduction" in this context, and what is an example of one that can exploit a few low-order bits of the quotient?

Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319
  • Seems to have to do with efficient computation of transcendental functions numerically by "reducing" the argument into a smaller range and using lookups and interpolation. See [these](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.123.9012&rep=rep1&type=pdf) [two](http://www.imada.sdu.dk/~kornerup/papers/RR2.pdf) papers. – Kerrek SB Jun 17 '12 at 23:30

1 Answers1

7

Argument reduction means mapping the argument of a periodic function into the canonical period (for example, (-π,π] or similar). If you used π/2 as the divisor, the low bits of the quotient would be sufficient for determining the right sign/etc. for trig functions.

Unfortunately, however, remquo is useless for implementing standard trigonometric argument reduction, because π is irrational; reducing large arguments modulo an approximation of π will give you results with no significant bits, i.e. all error.

If however you're writing a function f(x) defined as sin(πx) or similar, the period is now exactly representable in floating point, and remquo can do exactly what you need, whereas calling sin(2*M_PI*x) directly will give results with no significant bits (i.e. all error) when x is large.

R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
  • 2
    To be clear, a proper remquo implementations returns exact results (with no error) given the arguments it is passed. The reason it is of limited use in reducing trigonometric arguments is it is impossible to pass it the value of π more precisely than it can be represented in a double (or in a long double for remquol). So the problem is on input, not in the function calculation. – Eric Postpischil Jun 19 '12 at 01:41
  • Indeed, it's not a bug in the way the function works; it's a fundamental limitation in the interface that makes it useless for the standard trig functions. – R.. GitHub STOP HELPING ICE Jun 19 '12 at 02:46