commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilles Sadowski <gil...@harfang.homelinux.org>
Subject Re: svn commit: r1179928 - in [...]
Date Fri, 07 Oct 2011 13:17:45 GMT
> >> 
> >> /**
> >> - * Sinc function.
> >> + * Sinc function, defined by <pre><code>
> >> + *
> >> + * sinc(x) = 1 if abs(x) < 1e-9;
> >> + *           sin(x) / x; otherwise
> >> + * </code></pre>
> > 
> > I would not document the first part of the alternative since it is an
> > implementation detail.  "1e-9" was chosen just because, with "double"
> > precision, the function value will be indistinguishable from 1. Strictly
> > speaking it is not part of the definition of "sinc". [This part of the
> > implementation could even be removed if it is deemed that we lose more time
> > doing the check than we gain when the user asks the value of points below
> > 1e-9.]
> > 
> > Also, there probably should not be a ";" after the statements.
> 
> If it a) makes a difference in the returned result and b) is correct (up to double equality),

I don't understand what you write here.

What I meant above is:
 For values < 1e-9, it does not make a difference at double precision whether
 the computation is done in full (sin(x) / x) or by assigning "1" directly.

> I think we should leave the check in

Yes, of course; the suggestion to remove it was a mistake (see below).

> and document it.   We should always document top-coding or other departures from the
formulas we define things by. 

I don't see why give a wrong definition since it makes no difference. The
definition of "sinc" is[1]:
  sinc(x) = sin(x) / x

To compute it, care must be taken to not divide by zero, thus the simplest
operational definition is[2]:
  sinc(x) = 1           if x = 0
            sin(x) / x  otherwise

The one in CM is an efficiency improvement (to avoid evaluation of a sine
and a division when the result is indistinguishable from the known result).

The rationale for the shortcut could be a code comment, but as a user-level
comment, it is confusing.


Gilles

> 
> I am fine changing the semicolons (which are being used as punctuation) to commas or
even dropping them altogether. 
> 
> Phil

[1] http://en.wikipedia.org/wiki/Sinc_function
[2] http://mathworld.wolfram.com/SincFunction.html

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message