Sine code for ANSI C

P

P.J. Plauger

If the argument x is around 709 then according to the theory that a
double number represents an interval, x represents quite a large
interval; for example +/- 2^-44 with IEEE 64 bit representation. Not
quite as bad as for the sine function, but you have to start thinking
whether or not a maths library should return results with full precision
or not.

According to that theory, yes. I've never disputed that. The issue
I keep coming back to, however, is that no programming language
standard I know of invites authors of math libraries to take
advantage of that theory. Rather, standards define a floating-point
value as its overt value -- summing the contributions of all the
mantissa bits, multiplying by the exponent, negating if negative.
Nowhere does it say that the argument is fuzzy and the result
should therefore reflect the fuzziness.

And in support of this viewpoint, any number of test suites actually
check the *quality* of a math library on the basis of how close
the actual function values are to the best internal representation
of the function value corresponding to the argument treated as an
exact value. I assure you that existing customers file bug reports
and potential customers stay away in droves when a library shows
up too many "errors" on these tests. Fuzz just don't cut it.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
 
P

P.J. Plauger

I think they're arguing from the notion that "the purpose of
computing is insight, not numbers."

That's nice. But you ain't gonna get squat in the way of insight
if your computer doesn't deliver on its promise to be damned fast
and highly accurate at carrying out your wishes. When R.W. Hamming
dropped that little aphorism, he was taking for granted that the
computer would fulfill its part of the bargain. He was reminding
the human users what they should be bringing to the party.
relative error is what?

Roughly +/- 2^10 / 2^53. Or a loss of eleven bits out of 53.
What matters is the number of non-garbage bits.

On the input value? Yes, that's what matters to the *programmer*.
The library writer has no idea wheter there are *any* garbage
bits. We as a class are expected to assume there are none.
And people would like us to deliver results with *no* garbage
bits (assuming an exact input), so we don't add unnecessarily
to the problem.
Suppose that number were zero.

Which number? I'm supposing that the argument has no garbage
bits and that the highest quality implementation produces
no garbage bits for a function return value. Haven't heard
any better criterion yet.
To some degree, yes, but the case is far stronger for sin/cos.

Really? How? I've yet to hear an argument that doesn't apply
equally well to the other functions. If you're talking about
the *likelihood* that sin(700.0) is not a well thought out
function call, then I agree that it's more likely to be
nonsense than exp(700.0). But once again, *the C Standard doesn't
say so and the library author has to assume that both are valid
calls.* Nobody has given a concrete reason why the library author
should be let off the hook so far, IMO.
Let's stick to sin and cos. I haven't heard of one explicit
example of somebody who really thought about this and really
needed it.

And I have yet to have a customer call up and say that computing
exp(0.73) was *really* important. Is this a popularity contest
we're running, or are we trying to understand a programming
language specification?
By constrast, If I had a student writing some optics simulation
software, say simulating chaos in erbium-doped fiber ring lasers, if
he or she took sin or cos() of a very large value, they were making a
clear error by doing so. It conceivably could happen if they
implemented some textbook formulae naively.

Agreed. What has that to do with the requirements on writing the
Standard C library? We have to be sure to sort zero items properly
with qsort, but if I ever saw a student program that explicitly
called qsort for zero items I'd know s/he was confused. Such
examples are irrelevant to the requirements placed on library
writers.
I would feel more comfortable if the library automatically signaled
this, as it would be an instructive point, and it might prevent
wasted calculation or worse, an improper scientific inference.

So would I. But I've yet to hear presented here a concrete, *defensible*
definition of where "this" cuts in for sine.
who would complain, and what would be the particular application
they'd complain about?

Not for me to say. If I told them their application was unimportant,
or poorly designed, or had bad feng shui, would that let me off the
hook?
Because the uses of sine are different, and rounding
produces useful results.

So too does sine and cosine quite often. Who are you to tell
somebody else that s/he doesn't know what s/he is doing?
You might be right that they *likely* don't know what they're
doing, but you'd be foolish to take that for granted from
the outset.
A programmer's conceptual blunder.

Okay, quantify that and reduce it to standardese and I'm all
for it.
relative error, and facts of actual use.

The relative errors for sin(700) and exp(700) are comparable,
as I just demonstrated (and as is obvious from a few lines
of calculus). "Facts of actual use" are anecdotal at best
and pure conjecture at worst. Whatever it is, it ain't math
and it ain't standardese.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
 
C

Christian Bau

"P.J. Plauger said:
According to that theory, yes. I've never disputed that. The issue
I keep coming back to, however, is that no programming language
standard I know of invites authors of math libraries to take
advantage of that theory. Rather, standards define a floating-point
value as its overt value -- summing the contributions of all the
mantissa bits, multiplying by the exponent, negating if negative.
Nowhere does it say that the argument is fuzzy and the result
should therefore reflect the fuzziness.

And in support of this viewpoint, any number of test suites actually
check the *quality* of a math library on the basis of how close
the actual function values are to the best internal representation
of the function value corresponding to the argument treated as an
exact value. I assure you that existing customers file bug reports
and potential customers stay away in droves when a library shows
up too many "errors" on these tests. Fuzz just don't cut it.

Actually, what I meant was: With the exp function for large arguments as
an example, you have to make up your mind if you want to be lazy and
return results with an error of several hundred ulps under the
assumption that no one cares, or whether you want to produce quality
results. In this case, I would prefer quality.

In the end, errors tend to add up. Even if the calculation of x included
some significant rounding error, that is no good reason why the
calculation of exp (x) should add more error to this than absolutely
necessary.
 
D

Dan Pop

In said:
Actually, what I meant was: With the exp function for large arguments as
an example, you have to make up your mind if you want to be lazy and
return results with an error of several hundred ulps under the
assumption that no one cares, or whether you want to produce quality
results. In this case, I would prefer quality.

Me too, it's just that our notions of "quality" differ: a result with
garbage bits presented as precision bits and obtained by wasting cpu
resources is a low quality result.
In the end, errors tend to add up. Even if the calculation of x included
some significant rounding error, that is no good reason why the
calculation of exp (x) should add more error to this than absolutely
necessary.

This statement makes sense *only* if one considers floating point
representations as standing for precise mathematical values. This doesn't
happen to be the case (when was the last time all your input consisted
exclusively of values exactly representable in the target floating point
types?). For all you know, the result with "more error
than absolutely necessary" may be the *exact* result to the actual
problem. If you don't understand this statement, you shouldn't be
dealing with floating point values...

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top