[ntp:questions] Loopstats jitter field mostly zero?
Charles Elliott
elliott.ch at verizon.net
Sat Jan 12 02:51:12 UTC 2013
Your could make one up, for integer arithmetic; the method does not work for
floating point. The method is called low-cost inverse residue codes and is
in Avižienis, A. (1971). Arithmetic Error Codes: Cost and Effectiveness
Studies for Application in Digital System Design. Reliable Computer Systems:
Design and Evaluation. D. P. Siewiorek and R. S. Swarz. Burlington,
Massachusetts, Digital Press: 787-802.
Complete algorithms for the method are given on pp. 124-129 of Wakerly, J.
(1978). Error Detecting Codes, Self-Checking Circuits and Applications. New
York, New York, North-Holland.
For floating point sqrt you could do a few iterations to Netwon's method to
refine the
result returned by the built-in sqrt routine. If the refinement and the
result returned from sqrt agree to within a tolerance, then the sqrt routine
works. Here is a Netwon-Raphson algorithm in Java that is accurate:
public class NewtonRaphsonSqrt {
public double compute(double x, double guess, double tol, int maxIters)
throws IllegalArgumentException
{
double retVal = -1;
int i = 0;
if( (x < 0) || (maxIters < 1) || (tol < Math.ulp(guess)) )
throw new IllegalArgumentException("An argument is out of range.");
while( i <= maxIters ){
double p = guess + (x/guess - guess) / 2;
if( Math.abs(p - guess) < tol ){
retVal = Math.abs(p);
break;
}
else{
++i;
guess = p;
}
}
return retVal;
}
}
public class Test{
public static void main(String[] args) {
double x = 2.0;
NewtonRaphsonSqrt nrs = new NewtonRaphsonSqrt();
try{
double ans = nrs.compute(x, 1.1, 1e-6, 30);
System.out.printf("The square root of %f is %f%n", x, ans);
}catch( IllegalArgumentException e ){
e.printStackTrace();
System.exit(4);
}
System.exit(0);
}
}
Your could also Google "square root approximation algorithm" and find
several others.
Charles Elliott
> -----Original Message-----
> From: questions-bounces+elliott.ch=verizon.net at lists.ntp.org
> [mailto:questions-bounces+elliott.ch=verizon.net at lists.ntp.org] On
> Behalf Of james machado
> Sent: Friday, January 11, 2013 2:15 AM
> To: Charles Swiger
> Cc: david-taylor at blueyonder.co.uk; questions at lists.ntp.org
> Subject: Re: [ntp:questions] Loopstats jitter field mostly zero?
>
> On Tue, Jan 8, 2013 at 6:01 AM, Charles Swiger <cswiger at mac.com> wrote:
> > Hi--
> >
> > On Jan 8, 2013, at 2:16 AM, David Taylor <david-
> taylor at blueyonder.co.uk.invalid> wrote:
> >> Thanks, Harlan. I see that a function SQRT() is used, and that this
> function is defined as sqrt() in ntp.h:
> >>
> >> #define SQRT(x) (sqrt(x))
> >>
> >> I recall seeing /something/ about hardware and software floating
> point support in the Raspberry Pi, that some hardware/firmware/software
> had it and some not.
> >
> > AFAIK, all of the Raspberry Pis are using an ARM1176JZF-S CPU. The J
> means Jazelle (aka ThumbEE); dunno about the Z; the F means H/W
> floating point (aka VFP); S means the TrustZone Security Extensions:
> >
> >
> http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0301h/in
> dex.html
> >
> >> I wonder whether that might be the cause? I can't imagine sqrt()
> being broken, but maybe for very small numbers it's wrongly returning
> zero? Single precision versus double precision? As you know, I'm well
> out of my depth on this, but could there be a configuration flag to use
> software FP rather than hardware? I wonder how best to go about
> solving this problem?
> >
> > Well, there are software floating point and H/W testing software
> available which one might use to check:
> >
> > http://www.jhauser.us/arithmetic/TestFloat.html
> > http://www.netlib.org/fp/ (see UCBTEST)
>
> i've spent the last two days trying to get the UCBTEST to compile on
> the RPi with no luck. there are some defines the ieee.c file wants
> that I just don't grok. As far as TestFloat it requires SoftFloat
> which has fallen off the interwebs. If you have another test you
> would like me to try let me know.
>
> >
> > Regards,
> > --
> > -Chuck
> >
> > _______________________________________________
> > questions mailing list
> > questions at lists.ntp.org
> > http://lists.ntp.org/listinfo/questions
>
> james
> _______________________________________________
> questions mailing list
> questions at lists.ntp.org
> http://lists.ntp.org/listinfo/questions
More information about the questions
mailing list